Skip to content

Commit

Permalink
Add reproducer for #8149
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim-Pohlmann committed Oct 5, 2023
1 parent 176773c commit 0a5e030
Showing 1 changed file with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -510,3 +510,34 @@ public void TestMethod()

private void Callback() { }
}

// https://github.com/SonarSource/sonar-dotnet/issues/8149
public class Repro_8149
{
enum UserType
{
Internal,
External,
Other
}

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

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

0 comments on commit 0a5e030

Please sign in to comment.