Skip to content

Commit

Permalink
S2589 FP: Add reproducer for #8326 (#8327)
Browse files Browse the repository at this point in the history
Co-authored-by: Zsolt Kolbay <121798625+zsolt-kolbay-sonarsource@users.noreply.github.com>
  • Loading branch information
2 people authored and sebastien-marichal committed Nov 10, 2023
1 parent e6d52cf commit 7a99abc
Showing 1 changed file with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -543,3 +543,27 @@ void Check_SwitchExpression(IUser user)
throw new ApplicationException("not authorized");
}
}

// https://github.com/SonarSource/sonar-dotnet/issues/8326
class Repro_8326
{
void Test(int i, object o)
{
_ = i switch
{
1 => 1,
var other => 2 // Noncompliant {{Change this condition so that it does not always evaluate to 'True'.}} FP: var should not raise
};

_ = o switch
{
1 => 1,
var other => 2 // Compliant: by accident, o has no SymbolicValue and always branches due to #8324
};

if (i is var x1) // Noncompliant {{Change this condition so that it does not always evaluate to 'True'. Some code paths are unreachable.}}
Console.WriteLine();
else
Console.WriteLine(); // Secondary
}
}

0 comments on commit 7a99abc

Please sign in to comment.