-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Adjust semantic model for method group conversion #75719
Conversation
146f4ac
to
4edb67b
Compare
4edb67b
to
03f70f7
Compare
@@ -4294,6 +4294,12 @@ private OneOrMany<Symbol> GetMethodGroupSemanticSymbols( | |||
// we want to get the symbol that overload resolution chose for M, not the whole method group M. | |||
var conversion = (BoundConversion)boundNodeForSyntacticParent; | |||
|
|||
if (conversion.ConversionKind is not ConversionKind.MethodGroup && conversion.Operand is BoundConversion nestedConversion) |
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.
Nit:
if (conversion.ConversionKind is not ConversionKind.MethodGroup && conversion.Operand is BoundConversion nestedConversion) | |
if (conversion is { ConversionKind: not ConversionKind.MethodGroup, Operand: BoundConversion nestedConversion }) | |
``` #Resolved |
@jcouv Was this a regression? |
@@ -425,6 +426,112 @@ static void Main() | |||
Assert.True(conversion.IsNumeric); | |||
} | |||
|
|||
[Fact, WorkItem("https://github.com/dotnet/roslyn/issues/36377")] | |||
public void GetSymbolInfo_ExplicitCastOnMethodGroup() |
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.
Consider adding a similar test for VB #Closed
|
||
public static int Test() => 1; | ||
|
||
public static explicit operator C(System.Func<int> intDelegate) |
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.
Done. There are some existing unexpected behaviors there. Filing issues for those
@@ -4294,6 +4294,12 @@ private OneOrMany<Symbol> GetMethodGroupSemanticSymbols( | |||
// we want to get the symbol that overload resolution chose for M, not the whole method group M. | |||
var conversion = (BoundConversion)boundNodeForSyntacticParent; | |||
|
|||
if (conversion.ConversionKind is not ConversionKind.MethodGroup && conversion.Operand is BoundConversion nestedConversion) |
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.
@@ -4294,6 +4294,12 @@ private OneOrMany<Symbol> GetMethodGroupSemanticSymbols( | |||
// we want to get the symbol that overload resolution chose for M, not the whole method group M. | |||
var conversion = (BoundConversion)boundNodeForSyntacticParent; | |||
|
|||
if (conversion.ConversionKind is not ConversionKind.MethodGroup && conversion.Operand is BoundConversion nestedConversion) | |||
{ | |||
Debug.Assert(conversion.ConversionKind is ConversionKind.NoConversion || conversion.ExplicitCastInCode); |
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.
Debug.Assert(conversion.ConversionKind is ConversionKind.NoConversion || conversion.ExplicitCastInCode);
It is not obvious why is it reasonable to make this assumption. And more importantly why do we need to make it. If we are going after a specific bound tree shape, I think we should be checking for that instead. For example, we might want to confirm that the nested conversion is the immediate conversion for the BoundMethodGroup boundNode
. If that is not the case, switching the conversion node doesn't feel appropriate. #Closed
if (conversion.ConversionKind is not ConversionKind.MethodGroup && conversion.Operand is BoundConversion nestedConversion) | ||
{ | ||
Debug.Assert(conversion.ConversionKind is ConversionKind.NoConversion || conversion.ExplicitCastInCode); | ||
conversion = nestedConversion; |
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.
Done with review pass (commit 1) |
Perhaps this should be converted into a real check? Basically, we are interested in a method group conversion and we should check for that rather than assume that this is what we have. #Closed Refers to: src/Compilers/CSharp/Portable/Compilation/CSharpSemanticModel.cs:4306 in 03f70f7. [](commit_id = 03f70f7, deletion_comment = False) |
Nothing indicates that in the linked issue (filed in 2019). |
var tree = comp.SyntaxTrees.Single(); | ||
var model = comp.GetSemanticModel(tree); | ||
var memberAccess = GetSyntax<MemberAccessExpressionSyntax>(tree, "C.Test"); | ||
Assert.Equal("C C.op_Implicit(System.Func<System.Int32> intDelegate)", model.GetSymbolInfo(memberAccess).Symbol.ToTestDisplayString()); // Unexpected: Should be "void C.Test()" |
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.
Opened #75833
Dim x As C = DirectCast(AddressOf C.Test, C) | ||
~~~~~~~~~~~~~~~~ | ||
</expected>) | ||
End Sub |
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.
Done with review pass (commit 2) |
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 4)
Fixes #36377
In the scenario, we have a user-defined conversion for cast, stacked with a method group conversion.