-
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
Exclude identifiers in misplaced attributes from identifier map #75100
Conversation
@@ -2028,6 +2028,7 @@ static void addIdentifiers(CSharpSyntaxNode? node, ConcurrentDictionary<Identifi | |||
case GotoStatementSyntax { RawKind: (int)SyntaxKind.GotoStatement }: | |||
case TypeParameterConstraintClauseSyntax: | |||
case AliasQualifiedNameSyntax: | |||
case AttributeListSyntax: |
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 guess I should have added a comment that logic in this lambda is based on Binder.IdentifierUsedAsValueFinder.CheckIdentifiersInNode.childrenNeedChecking
. It can be more permissive (i.e. allow us to dive into more nodes), but should not be more restrictive. Since childrenNeedChecking
has the following case:
case AttributeListSyntax:
// References in attributes, if any, are errors
// Skip them
return false;
I am fine with adding a similar case here with the same comment/explanation. Given the sated goal "Predict all identifiers in the body that should go through Binder.BindIdentifier method", putting it into the bucket of "uninteresting" nodes is somewhat misleading because it contains identifiers that go through Binder.BindIdentifier.
At the same time, I would prefer an alternative approach to suppressing the assert. The one that will allow assertBindIdentifierTargets
to be closer to achieving the stated goal (quoted above).
assertBindIdentifierTargets
already disables asserts in presence of errors since there is no guaranty that we bind all the identifiers that are supposed to be bound. The scenarios that we are dealing with are actually error scenarios, we skip binding the attributes, but report a warning instead. That is why assertBindIdentifierTargets
fails to disable the check. I suggest to fix this flaw instead. I'll make a specific suggestion at the relevant location.
#Closed
It looks like adding the following code at the end of body of this
|
@@ -1651,6 +1651,11 @@ void adjustIdentifierMapIfAny(SimpleNameSyntax node, bool invoked) | |||
Binder current = this; | |||
while (current is not (null or InMethodBinder { IdentifierMap: not null })) | |||
{ | |||
if (current is ContextualAttributeBinder) |
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) |
@dotnet/roslyn-compiler for second review. Thanks |
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)
While merging, consider adjusting commit's title and comment to align them with the latest revision. |
Yup. Already done :-) |
@dotnet/roslyn-compiler for second review. Thanks |
Fixes #73905
For context:
buildIdentifierMapOfBindIdentifierTargets
builds a map of identifiers that we expect to bindadjustIdentifierMapIfAny
updates the map to record which identifiers we actually boundassertBindIdentifierTargets
checks the resulting map (already ignored identifiers in presence of binding errors, but now also skips identifiers in presence of warning for misplaced attributes, which causes attributes not to be bound)SynthesizedPrimaryConstructor.GetCapturedParameters