This repository was archived by the owner on Apr 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 133
Bug fixes #418
Merged
Merged
Bug fixes #418
Changes from 4 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
719498d
Restore overloads caching semantic
213b842
Merge branch 'master' of https://github.com/Microsoft/python-language…
beb6819
Bug fixes
3e92388
Null checks and better initialize and return locations
81b5f04
CR feedback
1610e90
More checks
698043a
Couple more checks
953b451
Move check to MemberResult
91532fd
Check
992b5bd
Simplify
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -129,17 +129,15 @@ public override PythonMemberType MemberType { | |
} | ||
|
||
|
||
internal override void AddReference(Node node, AnalysisUnit analysisUnit) { | ||
_references.GetReferences(analysisUnit.ProjectEntry as ProjectEntry)?.AddReference(new EncodedLocation(analysisUnit, node)); | ||
} | ||
internal override void AddReference(Node node, AnalysisUnit analysisUnit) | ||
=> _references.GetReferences(analysisUnit.ProjectEntry as ProjectEntry)?.AddReference(new EncodedLocation(analysisUnit, node)); | ||
|
||
public override IEnumerable<ILocationInfo> Locations { | ||
get { | ||
ReferenceList defns; | ||
if (!_references.TryGetValue(DeclaringModule, out defns)) { | ||
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(); | ||
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: 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 |
||
} | ||
} | ||
|
||
|
@@ -151,17 +149,14 @@ public override void AugmentAssign(AugmentedAssignStatement node, AnalysisUnit u | |
} | ||
} | ||
|
||
public override IAnalysisSet Await(Node node, AnalysisUnit unit) { | ||
return AnalysisSet.UnionAll(_protocols.Select(p => p.Await(node, unit))); | ||
} | ||
public override IAnalysisSet Await(Node node, AnalysisUnit unit) | ||
=> AnalysisSet.UnionAll(_protocols.Select(p => p.Await(node, unit))); | ||
|
||
public override IAnalysisSet BinaryOperation(Node node, AnalysisUnit unit, PythonOperator operation, IAnalysisSet rhs) { | ||
return AnalysisSet.UnionAll(_protocols.Select(p => p.BinaryOperation(node, unit, operation, rhs))); | ||
} | ||
public override IAnalysisSet BinaryOperation(Node node, AnalysisUnit unit, PythonOperator operation, IAnalysisSet rhs) | ||
=> AnalysisSet.UnionAll(_protocols.Select(p => p.BinaryOperation(node, unit, operation, rhs))); | ||
|
||
public override IAnalysisSet Call(Node node, AnalysisUnit unit, IAnalysisSet[] args, NameExpression[] keywordArgNames) { | ||
return AnalysisSet.UnionAll(_protocols.Select(p => p.Call(node, unit, args, keywordArgNames))); | ||
} | ||
public override IAnalysisSet Call(Node node, AnalysisUnit unit, IAnalysisSet[] args, NameExpression[] keywordArgNames) | ||
=> AnalysisSet.UnionAll(_protocols.Select(p => p.Call(node, unit, args, keywordArgNames))); | ||
|
||
public override void DeleteMember(Node node, AnalysisUnit unit, string name) { | ||
foreach (var p in _protocols) { | ||
|
@@ -273,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.
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; | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.