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

IDE0072: False positive when using switch expression over a Nullable<T>, where both null and T cases are present #50983

Closed
airbreather opened this issue Feb 3, 2021 · 0 comments · Fixed by #74018
Labels
Area-IDE Bug Feature - IDE0072 Populate switch expression help wanted The issue is "up for grabs" - add a comment if you are interested in working on it IDE-CodeStyle Built-in analyzers, fixes, and refactorings
Milestone

Comments

@airbreather
Copy link

airbreather commented Feb 3, 2021

Version Used:
.NET SDK 5.0.102

Steps to Reproduce:
dotnet build the following:

Program.cs

double? DivideByTwo(ulong? x)
{
    return x switch
    {
        null => null,
        ulong val => val / 2.0,
    };
}

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 default case (discard) at the end.

Based on #50982 (comment), I suspect that this may have the same root cause as both that issue and #48876, but I'm logging it separately for now just in case it does happen to be different enough.

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Feb 3, 2021
@jinujoseph jinujoseph added Bug help wanted The issue is "up for grabs" - add a comment if you are interested in working on it IDE-CodeStyle Built-in analyzers, fixes, and refactorings and removed untriaged Issues and PRs which have not yet been triaged by a lead labels Feb 10, 2021
@jinujoseph jinujoseph added this to the Backlog milestone Feb 10, 2021
@CyrusNajmabadi CyrusNajmabadi added the Feature - IDE0072 Populate switch expression label Nov 1, 2022
@github-project-automation github-project-automation bot moved this to Completed in Small Fixes Aug 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE Bug Feature - IDE0072 Populate switch expression help wanted The issue is "up for grabs" - add a comment if you are interested in working on it IDE-CodeStyle Built-in analyzers, fixes, and refactorings
Projects
Status: Completed
3 participants