-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extensions: account for new extensions in function type scenarios #77755
Conversation
// For lookup APIs in the semantic model, we can return symbols that aren't fully inferred. | ||
// But for function type inference, if the symbol isn't fully inferred with the information we have (the receiver and any explicit type arguments) | ||
// then we won't return it. | ||
internal static Symbol? GetReducedAndFilteredSymbol(this Symbol member, ImmutableArray<TypeWithAnnotations> typeArguments, TypeSymbol receiverType, CSharpCompilation compilation, bool checkFullyInferred) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📝 This logic is extracted from AddReducedAndFilteredSymbol
, but the check for "fully inferred" was added.
if (node.ResultKind == LookupResultKind.Viable) | ||
{ | ||
var methods = ArrayBuilder<MethodSymbol>.GetInstance(capacity: node.Methods.Length); | ||
foreach (var memberMethod in node.Methods) | ||
{ | ||
switch (node.ReceiverOpt) | ||
{ | ||
case BoundTypeOrValueExpression: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📝 Fixed a bug here. The relevant test is FunctionType_ColorColorReceiver_04
.
@AlekseyTs @jjonescz for review. Thanks |
} | ||
|
||
[Fact] | ||
public void Params_ExtensionScopes_01() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM (commit 1)
} | ||
} | ||
|
||
if ((object)constructed == null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks unnecessary since we return constructed
below anyway. #Resolved
Debug.Assert(property.GetIsNewExtensionMember()); | ||
var constructedProperty = (PropertySymbol)SourceNamedTypeSymbol.GetCompatibleSubstitutedMember(compilation, property, receiverType)!; | ||
|
||
if (constructedProperty is null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar comment. #Resolved
if (member is MethodSymbol method) | ||
{ | ||
// 1. construct with explicit type arguments if provided | ||
MethodSymbol constructed; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be nullable? We seem to be comparing constructed
to null
in several places below.
MethodSymbol constructed; | |
MethodSymbol? constructed; | |
``` #Resolved |
// infer type arguments based off the receiver type if needed, check applicability | ||
Debug.Assert(receiverType is not null); | ||
Debug.Assert(property.GetIsNewExtensionMember()); | ||
var constructedProperty = (PropertySymbol)SourceNamedTypeSymbol.GetCompatibleSubstitutedMember(compilation, property, receiverType)!; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we suppress nullability here but compare with null
below? #Resolved
else | ||
{ | ||
Debug.Assert(method.GetIsNewExtensionMember()); | ||
constructed = (MethodSymbol)SourceNamedTypeSymbol.GetCompatibleSubstitutedMember(compilation, constructed, receiverType)!; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we be also checking this result for null
instead of suppressing nullability? Since we do that below for properties. #Resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. Thanks. Added a test that hits that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM (commit 2)
Relates to test plan #76130