Skip to content

Conversation

@John-Leitch
Copy link
Contributor

@John-Leitch John-Leitch commented Jun 1, 2025

This PR fixes multi-variable declaration support in RemoveUnnecessarySuppressions by preventing redundant evaluation of symbols from variable declaration nodes containing more than one variable.

Fixes #78786

@John-Leitch John-Leitch requested a review from a team as a code owner June 1, 2025 16:11
@dotnet-policy-service dotnet-policy-service bot added Community The pull request was submitted by a contributor who is not a Microsoft employee. VSCode labels Jun 1, 2025
[WorkItem("https://github.com/dotnet/roslyn/issues/78786")]
public async Task TestRemoveDiagnosticSuppression_Attribute_MultiVariableDeclaration(MultiVariableTestKind testKind)
{
var (keyword, type) = testKind switch
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't overengineere, just make keyword and type test parameters directly

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simplified with InlineDataAttribute.

@DoctorKrolic
Copy link
Contributor

Also please add "Fixes #78786" to your PR description, so that GH automatically links that issue with the PR and closes it when the PR is merged

John-Leitch and others added 3 commits June 1, 2025 12:44
Co-authored-by: DoctorKrolic <70431552+DoctorKrolic@users.noreply.github.com>
@John-Leitch John-Leitch requested a review from DoctorKrolic June 1, 2025 16:49
@CyrusNajmabadi
Copy link
Member

Unclear why we need a loop in the first place. If we're just going to break when we have multiple. Why not just process the first symbol only?

@John-Leitch
Copy link
Contributor Author

John-Leitch commented Jun 1, 2025

Unclear why we need a loop in the first place. If we're just going to break when we have multiple. Why not just process the first symbol only?

I assumed it was there for a reason, but now that you mention it, I don't see why. None of the tests seem to get more than one symbol except the case I've added, so they all pass just checking the first. Not sure if there are uncovered case though.

@CyrusNajmabadi
Copy link
Member

Ok. Can you change to no loop, with a comment explaining why that is desirable here? Thanks!

…op and fixed partial method/property support in AbstractRemoveUnnecessaryInlineSuppressionsDiagnosticAnalyzer.
@John-Leitch
Copy link
Contributor Author

Updated as requested. However, upon doing some testing to confirm the safety of checking only the first symbol, I caught a variant of the issue that is triggered by partial methods and props. I've included a fix for that as well as some test coverage.

@CyrusNajmabadi CyrusNajmabadi enabled auto-merge June 2, 2025 03:39
@CyrusNajmabadi CyrusNajmabadi merged commit ca392a2 into dotnet:main Jun 2, 2025
24 of 25 checks passed
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Jun 2, 2025
@CyrusNajmabadi
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-Analyzers Community The pull request was submitted by a contributor who is not a Microsoft employee. VSCode

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Crash in RemoveUnnecessarySuppressions caused by multi-variable declaration

4 participants