Repository navigation
Avoid duplicate syntax node callbacks for record declarations - #58482
Conversation
Fixes dotnet#53136 Verified that the added unit test fails with duplicate diagnostics before the product fix.
|
@mavasani Do we have similar issue with top-level statements? |
…x node when analyzing synthesized record constructor.
@AlekseyTs - did you mean issue with records as top-level statements or just top-level statements in general? I am not really sure about the existing behavior for either of these, but can verify and add tests as appropriate. It would be helpful if you can also point me to any existing test files with analyzer tests for top-level statements, if you are aware. |
|
Here is a seemingly suspicious assert: roslyn/src/Compilers/CSharp/Test/Semantic/Semantics/SimpleProgramsTests.cs Lines 5111 to 5122 in 80d7e32 Specifically, both Here is where those counters are incremented: roslyn/src/Compilers/CSharp/Test/Semantic/Semantics/SimpleProgramsTests.cs Lines 5189 to 5199 in 80d7e32 So it looks like |
Thanks @Youssef1313. That confirms similar issue exists with top-level statements. I am going to create a separate tracking issue and PR to address that one. |
There was a problem hiding this comment.
I think it's worth adding tests (or opening issues after confirming there is an issue) for syntax checked in this method:
-
SyntaxKind.CompilationUnit(there are already tests that likely need to be adjusted) -
SyntaxKind.RecordDeclaration(already done) -
SyntaxKind.RecordStructDeclaration(already done) -
SyntaxKind.PrimaryConstructorBaseType -
SyntaxKind.Parameter
No the question is not related to records in any way. I think we might have similar "duplicate syntax node callbacks" problem for top-level statements. In particular around a compilation unit node, it declares a namespace, an entry point method and its containing type at the same time. |
|
Thanks @AlekseyTs - I have filed #58561 for top-level statements. |
|
My intuition tells me that we are likely taking a "wrong" approach for achieving the goal. I feel like a better approach would be to revert relevant parts of #46308 instead of adding special APIs to neutralize their effect. We could simply remove the effect in the first place. I also think that it might make sense to deal with top level statements at the same time and in the same manner (finding the PR that changed the behavior for them), because they are likely to be closely related in terms of implementation strategy. Records probably build on top of what was added for top level statements, etc. And dealing with them together is likely to be much easier, more code can be removed at once rather than carefully trying to maintain an undesired behavior for one feature, but not for the other. In reply to: 1006710484 |
2f34134 to
9a54b6b
Compare
Youssef1313
left a comment
There was a problem hiding this comment.
Note: It might worth adding some comments around the interesting parts of code of #46308 so that whenever a developer adds a new syntax kind that is to cause a problem, hopefully the comment will remind the developer to have the appropriate fix.
9a54b6b to
8f2de20
Compare
|
Done with review pass (commit 5) |
AlekseyTs
left a comment
There was a problem hiding this comment.
LGTM (commit 7), assuming CI is passing.
|
Thanks @AlekseyTs! @dotnet/roslyn-compiler for second review. |
|
@dotnet/roslyn-compiler for second review. |
1 similar comment
|
@dotnet/roslyn-compiler for second review. |
|
Thank you @cston |
|
@AlekseyTs @Youssef1313 I will create a follow-up PR on the same lines for top level statements. |
… for files with top level statements Fixes dotnet#58561 Follow-up change to dotnet#58482
Fixes #53136
Verified that the added unit test fails with duplicate diagnostics before the product fix.