-
Notifications
You must be signed in to change notification settings - Fork 133
Bug fixes #418
Bug fixes #418
Changes from 1 commit
719498d
213b842
beb6819
3e92388
81b5f04
1610e90
698043a
953b451
91532fd
992b5bd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -137,7 +137,7 @@ public override IEnumerable<ILocationInfo> Locations { | |
| if (!_references.TryGetValue(DeclaringModule, out var defns)) { | ||
| return Enumerable.Empty<ILocationInfo>(); | ||
| } | ||
| return defns.Definitions.Select(l => l.GetLocationInfo()).Where(l => l != null); | ||
| return defns.Definitions.Select(l => l.GetLocationInfo()).ExcludeDefault(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like we have two almost identical methods:
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes |
||
| } | ||
| } | ||
|
|
||
|
|
@@ -268,85 +268,78 @@ public override bool Equals(object obj) { | |
|
|
||
| public override int GetHashCode() => ObjectComparer.Instance.GetHashCode(_protocols); | ||
|
|
||
| internal override bool UnionEquals(AnalysisValue av, int strength) { | ||
| if (av is ProtocolInfo pi) { | ||
| if (strength > 0) { | ||
| return Name == pi.Name; | ||
| } | ||
| return ObjectComparer.Instance.Equals(_protocols, pi._protocols); | ||
| } | ||
| return false; | ||
| } | ||
| internal override bool UnionEquals(AnalysisValue av, int strength) | ||
MikhailArkhipov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| => av is ProtocolInfo pi ? ObjectComparer.Instance.Equals(_protocols, pi._protocols) : false; | ||
|
|
||
| internal override int UnionHashCode(int strength) { | ||
| if (strength > 0) { | ||
| return Name.GetHashCode(); | ||
| } | ||
| return GetHashCode(); | ||
| internal override int UnionHashCode(int strength) { | ||
MikhailArkhipov marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if (strength > 0) { | ||
| return Name.GetHashCode(); | ||
| } | ||
| return GetHashCode(); | ||
| } | ||
|
|
||
| internal override AnalysisValue UnionMergeTypes(AnalysisValue av, int strength) { | ||
| if (strength > 0 && av is ProtocolInfo pi && pi.Push()) { | ||
| try { | ||
| var name = _protocols.OfType<NameProtocol>().FirstOrDefault(); | ||
| if (_protocols.Count == 1 && name != null) { | ||
| return this; | ||
| } | ||
|
|
||
| var protocols = _protocols.Union(pi._protocols, out bool changed); | ||
| if (!changed) { | ||
| return this; | ||
| } | ||
| internal override AnalysisValue UnionMergeTypes(AnalysisValue av, int strength) { | ||
| if (strength > 0 && av is ProtocolInfo pi && pi.Push()) { | ||
| try { | ||
| var name = _protocols.OfType<NameProtocol>().FirstOrDefault(); | ||
| if (_protocols.Count == 1 && name != null) { | ||
| return this; | ||
| } | ||
|
|
||
| if (name != null) { | ||
| protocols.Split<NameProtocol>(out _, out protocols); | ||
| protocols = protocols.Add(name); | ||
| } | ||
| var protocols = _protocols.Union(pi._protocols, out bool changed); | ||
| if (!changed) { | ||
| return this; | ||
| } | ||
|
|
||
| return new ProtocolInfo(DeclaringModule, State) { | ||
| _protocols = protocols | ||
| }; | ||
| } finally { | ||
| pi.Pop(); | ||
| if (name != null) { | ||
| protocols.Split<NameProtocol>(out _, out protocols); | ||
| protocols = protocols.Add(name); | ||
| } | ||
| } | ||
|
|
||
| return this; | ||
| return new ProtocolInfo(DeclaringModule, State) { | ||
| _protocols = protocols | ||
| }; | ||
| } finally { | ||
| pi.Pop(); | ||
| } | ||
| } | ||
|
|
||
| public virtual IEnumerable<KeyValuePair<string, string>> GetRichDescription() { | ||
| var names = _protocols.OfType<NameProtocol>().ToArray(); | ||
| Debug.Assert(names.Length <= 1, "Multiple names are not supported"); | ||
| var name = names.FirstOrDefault(); | ||
| if (name != null) { | ||
| return name.GetRichDescription(); | ||
| } | ||
| return this; | ||
| } | ||
|
|
||
| var res = new List<KeyValuePair<string, string>>(); | ||
| var namespaces = _protocols.OfType<NamespaceProtocol>().ToArray(); | ||
| var tuples = _protocols.OfType<TupleProtocol>().ToArray(); | ||
| var other = _protocols.OfType<Protocol>().Except(names).Except(namespaces).ToArray(); | ||
|
|
||
| if (namespaces.Any()) { | ||
| var addComma = false; | ||
| res.Add(new KeyValuePair<string, string>(WellKnownRichDescriptionKinds.Misc, "(")); | ||
| foreach (var p in namespaces) { | ||
| if (addComma) { | ||
| res.Add(new KeyValuePair<string, string>(WellKnownRichDescriptionKinds.Comma, ", ")); | ||
| } | ||
| addComma = true; | ||
| res.AddRange(p.GetRichDescription()); | ||
| public virtual IEnumerable<KeyValuePair<string, string>> GetRichDescription() { | ||
| var names = _protocols.OfType<NameProtocol>().ToArray(); | ||
| Debug.Assert(names.Length <= 1, "Multiple names are not supported"); | ||
| var name = names.FirstOrDefault(); | ||
| if (name != null) { | ||
| return name.GetRichDescription(); | ||
| } | ||
|
|
||
| var res = new List<KeyValuePair<string, string>>(); | ||
| var namespaces = _protocols.OfType<NamespaceProtocol>().ToArray(); | ||
| var tuples = _protocols.OfType<TupleProtocol>().ToArray(); | ||
| var other = _protocols.OfType<Protocol>().Except(names).Except(namespaces).ToArray(); | ||
|
|
||
| if (namespaces.Any()) { | ||
| var addComma = false; | ||
| res.Add(new KeyValuePair<string, string>(WellKnownRichDescriptionKinds.Misc, "(")); | ||
| foreach (var p in namespaces) { | ||
| if (addComma) { | ||
| res.Add(new KeyValuePair<string, string>(WellKnownRichDescriptionKinds.Comma, ", ")); | ||
| } | ||
| res.Add(new KeyValuePair<string, string>(WellKnownRichDescriptionKinds.Misc, ")")); | ||
| addComma = true; | ||
| res.AddRange(p.GetRichDescription()); | ||
| } | ||
| res.Add(new KeyValuePair<string, string>(WellKnownRichDescriptionKinds.Misc, ")")); | ||
| } | ||
|
|
||
| foreach (var p in other) { | ||
| res.AddRange(p.GetRichDescription().ToArray()); | ||
| } | ||
| foreach (var p in other) { | ||
| res.AddRange(p.GetRichDescription().ToArray()); | ||
| } | ||
|
|
||
| res.Add(new KeyValuePair<string, string>(WellKnownRichDescriptionKinds.EndOfDeclaration, string.Empty)); | ||
| res.Add(new KeyValuePair<string, string>(WellKnownRichDescriptionKinds.EndOfDeclaration, string.Empty)); | ||
|
|
||
| return res; | ||
| } | ||
| return res; | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,14 +9,15 @@ | |
| // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS | ||
| // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY | ||
| // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, | ||
| // MERCHANTABLITY OR NON-INFRINGEMENT. | ||
| // MERCHANTABILITY OR NON-INFRINGEMENT. | ||
| // | ||
| // See the Apache Version 2.0 License for specific language governing | ||
| // permissions and limitations under the License. | ||
|
|
||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using Microsoft.PythonTools.Analysis.Infrastructure; | ||
| using Microsoft.PythonTools.Interpreter; | ||
| using Microsoft.PythonTools.Parsing.Ast; | ||
|
|
||
|
|
@@ -208,52 +209,17 @@ public override bool IsOfType(IAnalysisSet klass) { | |
| return _original.IsOfType(klass); | ||
| } | ||
|
|
||
| public override IEnumerable<ILocationInfo> Locations { | ||
| get { | ||
| if (_original == null) { | ||
| return new LocationInfo[0]; | ||
| } | ||
| return _original.Locations; | ||
| } | ||
| } | ||
| public override IEnumerable<ILocationInfo> Locations => _original.Locations?.MaybeEnumerate(); | ||
MikhailArkhipov marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| public override string Name => _original == null ? base.Name : this._original.Name; | ||
| public override string Name => _original == null ? base.Name : _original.Name; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why in this case we call
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good question. No idea. |
||
|
|
||
| public override IEnumerable<OverloadResult> Overloads { | ||
| get { | ||
| if (_original == null) { | ||
| return new OverloadResult[0]; | ||
| } | ||
| return _original.Overloads; | ||
| } | ||
| } | ||
| public override IEnumerable<OverloadResult> Overloads =>_original.Overloads.MaybeEnumerate(); | ||
|
|
||
| public override IPythonType PythonType { | ||
| get { | ||
| if (_original == null) { | ||
| return null; | ||
| } | ||
| return _original.PythonType; | ||
| } | ||
| } | ||
| public override IPythonType PythonType => _original?.PythonType; | ||
|
|
||
| internal override IEnumerable<ILocationInfo> References { | ||
| get { | ||
| if (_original == null) { | ||
| return new LocationInfo[0]; | ||
| } | ||
| return _original.References; | ||
| } | ||
| } | ||
| internal override IEnumerable<ILocationInfo> References => _original.References?.MaybeEnumerate(); | ||
|
|
||
| public override PythonMemberType MemberType { | ||
| get { | ||
| if (_original == null) { | ||
| return PythonMemberType.Unknown; | ||
| } | ||
| return _original.MemberType; | ||
| } | ||
| } | ||
| public override PythonMemberType MemberType => _original == null ? PythonMemberType.Unknown : _original.MemberType; | ||
|
|
||
| public override IAnalysisSet ReverseBinaryOperation(Node node, AnalysisUnit unit, Parsing.PythonOperator operation, IAnalysisSet rhs) { | ||
| if (_original == null) { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.