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 S2259 FP: Raising issue in unreachable code when using declaration pattern on unknown value #8324

Closed
Tim-Pohlmann opened this issue Nov 7, 2023 · 0 comments · Fixed by #8488
Assignees
Labels
Area: C# C# rules related issues. Area: CFG/SE CFG and SE related issues. Type: CFG/SE FPs Rule IS triggered when it shouldn't be for CFG and SE rules.
Milestone

Comments

@Tim-Pohlmann
Copy link
Contributor

Tim-Pohlmann commented Nov 7, 2023

Do not fix this before #8326. By coincidence, it is suppressing a lot of FPs for S2589.

void Test(object o, int i)
{
    object n = null;
            
    if (i is var x1)
        Console.WriteLine();
    else
        Console.WriteLine(n.ToString());    // Compliant: unreachable
            
    if (o is var x2)
        Console.WriteLine();
    else
        Console.WriteLine(n.ToString());    // Noncompliant FP: unreachable
}

When the value of an IsPattern has no SymbolicValue, the engine will not learn anything even if the pattern will always/never match.
This behavior is caused by the IsPattern processor and documented in a unit test.

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. Area: CFG/SE CFG and SE related issues. Type: CFG/SE FPs Rule IS triggered when it shouldn't be for CFG and SE rules.
Projects
None yet
3 participants