-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Demonstrate issue with GetSymbolInfo and function pointers. #81135
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
base: main
Are you sure you want to change the base?
Conversation
|
@333fred i was debugging through #81113 The problem on the IDE side is that we try to call GetSymbolInfo on C.M and we get back a symbolinfo that says 'OverloadResolutionFailed' and only inccludes C.M() in the .CandidateSymbols not the .Symbol. This causes us to bail out as we don't want to simplify something in error. Can you ptal here? It seems odd that the code is entirely correct and compiles without error, but we get back a wonky SymbolInfo like this. I've included a debuggable test here for you in FunctionPointerTests. Thanks! |
333fred
left a comment
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.
What is the actual issue here?
| ); | ||
| } | ||
|
|
||
| [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/75933")] |
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.
How is this related to this issue?
| var memberAccess = root.DescendantNodes().OfType<MemberAccessExpressionSyntax>().Single(); | ||
| var symbolInfo = semanticModel.GetSymbolInfo(memberAccess); | ||
|
|
||
| Assert.NotNull(symbolInfo.Symbol); |
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.
Please assert ToTestDisplayString, not just not null. #Resolved
…t cast expression for bindable parent node.
| } | ||
|
|
||
| [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/81113")] | ||
| public void TestGetSymbolInfo_Parethesized() |
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's a typo in test name. Also the test doesn't seem useful as parens generally do nothing. I'd remove this 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.
The test is intentional to make sure we are walking through parentheses.
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.
Also, I don't know what typo you are referring to?
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.
Parethesized => Parenthesized
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.
I think the point is exactly that things work properly even in the presence of parens. We don't want a set of parens making it so that semantic info breaks again.
| } | ||
| break; | ||
|
|
||
| case SyntaxKind.AddressOfExpression: |
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.
I didn't understand the fix.
The method says "some nodes don't have direct semantic meaning by themselves and so we need to bind a different node that does"
But I don't follow why addressOf would fall in that category.
Also, it is strange that addressOf would be the only expression that needs special treatment for casts here.
If we bind the addressOf, what is wrong with the resulting bound node? (you could share .Dump() info from that node to illustrate the problem)
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.
As the comment says, when the bound tree involves an address of being the direct object of a cast, there is no boundnode for the address of in the tree at all. You have a BoundConversion, representing the (delegate*<void>)&C.M, and it's operand, a BoundMethodGroup representing C.M. Since there is no node in the tree for the &C.M itself, GetBoundNodes will do a fallback "there must be an error here" binding (
roslyn/src/Compilers/CSharp/Portable/Compilation/MemberSemanticModel.cs
Lines 2177 to 2191 in b28fc31
| if (results.IsEmpty) | |
| { | |
| // https://github.com/dotnet/roslyn/issues/35038: We have to run analysis on this node in some manner | |
| using (_nodeMapLock.DisposableWrite()) | |
| { | |
| var boundNode = this.Bind(incrementalBinder, node, BindingDiagnosticBag.Discarded); | |
| GuardedAddBoundTreeForStandaloneSyntax(node, boundNode); | |
| results = GuardedGetBoundNodesFromMap(node); | |
| } | |
| if (!results.IsEmpty) | |
| { | |
| return results; | |
| } | |
| } |
BoundUnconvertedAddressOf node that is marked as failing overload resolution.
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.
Thanks. Your explanation was clearer than comment :-P
|
There seems to be legitimate CI test failures Does this PR close issue #81113 ? |
src/Features/CSharpTest/SimplifyTypeNames/SimplifyTypeNamesTests.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Test/Semantic/Semantics/FunctionPointerTests.cs
Outdated
Show resolved
Hide resolved
jcouv
left a comment
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 Thanks (commit 5) modulo typo
|
i can't approve the PR, even though i didn't write the fix. |
|
@333fred seems like we have some failures in tests like: Microsoft.CodeAnalysis.CSharp.UnitTests.CodeGen.CodeGenFunctionPointersTests.AddressOf_CannotAssignToVoidStar |
|
Yes, I'm aware. This is going to need to be a bigger change to the bound tree. |
…sts.cs Co-authored-by: Julien Couvreur <[email protected]>
No description provided.