Skip to content

CS8655 (exhaustive enum) should be triggered for nullable enum values #76817

@juwens

Description

@juwens

Version Used: C#12

Steps to Reproduce:

  1. compile the sample code or test it in sharplab
#pragma warning disable CS8524

enum MyEnum { A }

class C
{
    void M()
    {
        bool? b = null;
        
        _ = b switch // <= correctly warns about missing null arm with CS8655
        {
            true => 1,
            false => 2,
        };
        
        
        MyEnum? x = null;
        
        _ = x switch // <= does NOT warn about missing null arm with CS8655
        {
            MyEnum.A => "A",
        };
    }
}

Diagnostic Id: CS8655: The switch expression does not handle some null inputs (it is not exhaustive).

If this is a report about a bug in an analyzer, please include the diagnostic ID and message if possible (e.g. "IDE0030: Use coalesce expression").

Expected Behavior: nullable enum-variable switch-expression with missing null should yield CS8655

Actual Behavior: nullable enum-variable switch-expression with missing null does NOT yield CS8655

Metadata

Metadata

Assignees

Type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions