-
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
Ensure to get the name of nameof argument #52016
Conversation
@@ -1874,7 +1874,7 @@ private void EnsureNameofExpressionSymbols(BoundMethodGroup methodGroup, Binding | |||
/// <summary> | |||
/// Returns true if syntax form is OK (so no errors were reported) | |||
/// </summary> | |||
private bool CheckSyntaxForNameofArgument(ExpressionSyntax argument, out string name, BindingDiagnosticBag diagnostics, bool top = true) | |||
private bool CheckSyntaxForNameofArgument(ExpressionSyntax argument, out string name, BindingDiagnosticBag diagnostics, bool boundArgumentHasAnyErrors, bool top = true) |
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.
bool boundArgumentHasAnyErrors [](start = 128, length = 30)
Instead of adding this parameter we should consider passing BindingDiagnosticBag.Discarded when we are trying to suppress cascading diagnostics. #Closed
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.
@AlekseyTs That simplifies it alot! 🎉
// We relax the instance-vs-static requirement for top-level member access expressions by creating a NameofBinder binder. | ||
var nameofBinder = new NameofBinder(argument, this); | ||
var boundArgument = nameofBinder.BindExpression(argument, diagnostics); | ||
if (!boundArgument.HasAnyErrors && CheckSyntaxForNameofArgument(argument, out name, diagnostics) && boundArgument.Kind == BoundKind.MethodGroup) | ||
var syntaxIsOk = CheckSyntaxForNameofArgument(argument, out string name, diagnostics, boundArgument.HasAnyErrors); |
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.
var syntaxIsOk = CheckSyntaxForNameofArgument(argument, out string name, diagnostics, boundArgument.HasAnyErrors); [](start = 12, length = 114)
We should add tests that observe this behavior change via SemanticModel/IOperation and possibly other APIs. #Closed
Done with review pass (commit 3) #Closed |
// We relax the instance-vs-static requirement for top-level member access expressions by creating a NameofBinder binder. | ||
var nameofBinder = new NameofBinder(argument, this); | ||
var boundArgument = nameofBinder.BindExpression(argument, diagnostics); | ||
if (!boundArgument.HasAnyErrors && CheckSyntaxForNameofArgument(argument, out name, diagnostics) && boundArgument.Kind == BoundKind.MethodGroup) | ||
|
||
bool syntaxIsOk = CheckSyntaxForNameofArgument(argument, out string name, boundArgument.HasAnyErrors ? BindingDiagnosticBag.Discarded : diagnostics); |
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 want to introduce a local for this conditional expression to prevent it from being used accidentally. (See few lines later which uses diagnostics
regardless syntaxIsOk
)
} | ||
Block[B2] - Exit | ||
Predecessors: [B1] | ||
Statements (0) | ||
"; | ||
VerifyFlowGraphAndDiagnosticsForTest<BlockSyntax>(source, expectedFlowGraph, expectedDiagnostics); |
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.
VerifyFlowGraphAndDiagnosticsForTest [](start = 12, length = 36)
Did you really mean to validate a flow graph or just copied "wrong" 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.
@AlekseyTs, Ah I think I wanted to validate the operation tree instead. But probably okay to keep it since the ILiteralOperation's constant value should be affected by this change. Let me know if this alone is sufficient, or if I should validate both flow graph and operation tree, or operation tree only.
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), modulo a question around IOperation test.
@dotnet/roslyn-compiler Please review. Need a second sign-off for a small community PR. |
3 similar comments
@dotnet/roslyn-compiler Please review. Need a second sign-off for a small community PR. |
@dotnet/roslyn-compiler Please review. Need a second sign-off for a small community PR. |
@dotnet/roslyn-compiler Please review. Need a second sign-off for a small community PR. |
Thanks @Youssef1313! |
Fixes #52013.