Open manpil opened 2 months ago
S2589 is raised on a switch expression on a tuple where the second parameter is discarded but for the first one there is a guard clause.
private static string Example(string input, bool y) { return (input, y) switch { ("Foo", true) => "FooTrue", ("Foo", false) => "FooFalse", (var x, true) when x.StartsWith("ab") => "AbTrue", (var x, _) when x.StartsWith("CD") => "CD", _ => "empty", }; }
S2589 is not raised
S2589 is raised on the line containing: (var x, _) when x.StartsWith("CD") => "CD",
None/ Disable with pragma
Kindof relates to: https://github.com/SonarSource/sonar-dotnet/issues/8008
Hello @manpil,
Thank you for reporting this issue. I confirm this is a false positive.
I am adding this issue to our backlog to tackle it in the future.
Have a good day!
Description
S2589 is raised on a switch expression on a tuple where the second parameter is discarded but for the first one there is a guard clause.
Repro steps
Expected behavior
S2589 is not raised
Actual behavior
S2589 is raised on the line containing: (var x, _) when x.StartsWith("CD") => "CD",
Known workarounds
None/ Disable with pragma
Related information
Kindof relates to: https://github.com/SonarSource/sonar-dotnet/issues/8008