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

Fix S2589 FP: Rule ignores case guards #9663

Open
manpil opened this issue Sep 13, 2024 · 1 comment
Open

Fix S2589 FP: Rule ignores case guards #9663

manpil opened this issue Sep 13, 2024 · 1 comment
Labels
Area: C# C# rules related issues. Type: CFG/SE FPs Rule IS triggered when it shouldn't be for CFG and SE rules.

Comments

@manpil
Copy link

manpil commented Sep 13, 2024

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

 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",
        };
    }

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

  • C#/VB.NET Plugins version: 9.32
  • Visual Studio version: N/A -> Rider 2024.2.4
  • MSBuild / dotnet version: .net8.0
  • SonarScanner for .NET version (if used): N/A
  • Operating System: Ubuntu 22.04 LTS

Kindof relates to: #8008

@sebastien-marichal
Copy link
Contributor

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!

@sebastien-marichal sebastien-marichal added Area: C# C# rules related issues. Type: CFG/SE FPs Rule IS triggered when it shouldn't be for CFG and SE rules. labels Sep 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: C# C# rules related issues. Type: CFG/SE FPs Rule IS triggered when it shouldn't be for CFG and SE rules.
Projects
None yet
Development

No branches or pull requests

2 participants