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: Switch Expression default case with bool literal #8149

Closed
Tim-Pohlmann opened this issue Oct 5, 2023 · 0 comments · Fixed by #8450
Closed

Fix S2589 FP: Switch Expression default case with bool literal #8149

Tim-Pohlmann opened this issue Oct 5, 2023 · 0 comments · Fixed by #8450
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 Oct 5, 2023

S2589 has an issue with certain switch expressions. Further investigation is required.

enum UserType
{
    Internal,
    External,
    Other
}

interface IUser
{
    int Id { get; }
    string LoginName { get; }
    UserType UserType { get; }
}

static class Program
{
    public static void Check_SwitchExpression(IUser user)
    {
        if (user.UserType switch                         // Noncompliant FP, always false
        {
            UserType.Internal => user.Id == 1,
            UserType.External => user.LoginName == "test",
            _ => false,
        })
            return;

        throw new ApplicationException("not authorized");
    }
}
@Tim-Pohlmann Tim-Pohlmann added Area: CFG/SE CFG and SE related issues. Area: C# C# rules related issues. Type: CFG/SE FPs Rule IS triggered when it shouldn't be for CFG and SE rules. Area: C#8 labels Oct 5, 2023
Tim-Pohlmann added a commit that referenced this issue Oct 5, 2023
Tim-Pohlmann added a commit that referenced this issue Oct 16, 2023
@Tim-Pohlmann Tim-Pohlmann added this to the 9.16 milestone Dec 6, 2023
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
Development

Successfully merging a pull request may close this issue.

2 participants