Skip to content
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

Stop RCS1031, RCS1208 and RCS1211 from being applied if the local variables overlap. #1039

Merged
merged 11 commits into from
Mar 19, 2023

Conversation

jamesHargreaves12
Copy link
Contributor

For cases, where the same local variable is declared inside the if and else blocks e.g.

if (flag)
{
    var x  = 1;
    return x;
}
else 
{
    var x = 0;
    return x;
}

The diagnostic RCS1211 Should not be raised.

Removing the else block would cause a compiler error "A local variable named 'x' cannot be declared in this scope because it would give a different meaning to 'x', which is already used in a parent or current scope to denote something else".

The same thing is true for switch case brackets (RCS1031).

@jamesHargreaves12 jamesHargreaves12 changed the title Stop RCS1031 and RCS1211 from being applied if the local variables overlap. Stop RCS1031, RCS1208 and RCS1211 from being applied if the local variables overlap. Feb 18, 2023
@josefpihrt
Copy link
Collaborator

Thanks for the PR! 👍

Haarmees pushed a commit to Haarmees/Roslynator that referenced this pull request Oct 30, 2023
…iables overlap. (dotnet#1039)

Co-authored-by: Josef Pihrt <josef@pihrt.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants