Skip to content

IDE0072: False positive when using switch expression and pattern matching with "or" #50982

@airbreather

Description

@airbreather

Version Used:
.NET SDK 5.0.102

Steps to Reproduce:
dotnet build the following:

Program.cs

bool EnumIsValid(FriendOrFoe f)
{
    return f switch
    {
        FriendOrFoe.Friend or FriendOrFoe.Foe => true,
        _ => false,
    };
}

enum FriendOrFoe
{
    Friend,
    Foe
}

ConsoleApp0.csproj

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net5.0</TargetFramework>
    <EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
  </PropertyGroup>

</Project>

.editorconfig

[*.cs]
dotnet_diagnostic.IDE0072.severity = warning

Expected Behavior:
IDE0072 is not raised: all cases are handled

Actual Behavior:
IDE0072 is raised. The suggested fix is to add a separate case for FriendOrFoe.Friend and a separate case for FriendOrFor.Foe.

Metadata

Metadata

Assignees

Labels

Area-IDEBughelp wantedThe issue is "up for grabs" - add a comment if you are interested in working on it

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions