Skip to content

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

Merged
josefpihrt merged 11 commits intodotnet:mainfrom
jamesHargreaves12:fix/RCS1031-and-RCS1211
Mar 19, 2023
Merged

Stop RCS1031, RCS1208 and RCS1211 from being applied if the local variables overlap.#1039
josefpihrt merged 11 commits intodotnet:mainfrom
jamesHargreaves12:fix/RCS1031-and-RCS1211

Conversation

@jamesHargreaves12
Copy link
Copy Markdown
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
Copy Markdown
Collaborator

Thanks for the PR! 👍

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