sonar-dotnet
sonar-dotnet copied to clipboard
Fix S1854 FP: Raises when variable is assigned in switch statement and not use in the first case
Repro steps
void Repro()
{
char ch;
switch (ch = GetAChar()) // Noncompliant FP
{
case 'A':
break;
case 'B':
Console.WriteLine(ch);
break;
default:
Console.WriteLine("Something");
break;
}
switch (ch = GetAChar()) // Does not raise
{
case 'A':
Console.WriteLine(ch);
break;
default:
Console.WriteLine("Something");
break;
}
char GetAChar() => 'c';
}