Skip to content

Handle null coalescing assign-to-self scenarios#58933

Merged
RikkiGibson merged 4 commits intodotnet:mainfrom
RikkiGibson:pnc-assign-self
Jan 19, 2022
Merged

Handle null coalescing assign-to-self scenarios#58933
RikkiGibson merged 4 commits intodotnet:mainfrom
RikkiGibson:pnc-assign-self

Conversation

@RikkiGibson
Copy link
Copy Markdown
Member

@RikkiGibson RikkiGibson commented Jan 18, 2022

Related to #36024

After running fix-all in Roslyn I noticed a few warnings in scenarios like the following:

void M(string s)
{
    s = s ?? throw new ArgumentNullException(nameof(s));
}

We fixed this by turning it into s = s; which is a warning (variable assigned to itself). Instead, what we should do is delete the entire statement in this case.

@ghost ghost added the Area-IDE label Jan 18, 2022
RikkiGibson and others added 2 commits January 18, 2022 15:37
Co-authored-by: CyrusNajmabadi <cyrus.najmabadi@gmail.com>
…UseParameterNullCheckingDiagnosticAnalyzer.cs

Co-authored-by: CyrusNajmabadi <cyrus.najmabadi@gmail.com>
@RikkiGibson RikkiGibson enabled auto-merge (squash) January 19, 2022 00:03
@RikkiGibson RikkiGibson merged commit 7b6b572 into dotnet:main Jan 19, 2022
@ghost ghost added this to the Next milestone Jan 19, 2022
@RikkiGibson RikkiGibson deleted the pnc-assign-self branch January 19, 2022 03:57
@RikkiGibson RikkiGibson modified the milestones: Next, 17.2.P1 Feb 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants