Skip to content

Invalid IDE0004 on cast in switch expression #42108

@drewnoakes

Description

@drewnoakes

Version Used: Version 16.6.0 Preview 2.0 (master) (private branch build with unrelated changes)

Steps to Reproduce:

enum E { A, B }

class C
{
    bool M(int i)
    {
        return (E)i switch
        //     ~~~ IDE0004 cast is redundant
        {
            E.A => true,
            _ => false
        };
    }
}

Expected Behavior:

Cast is not flagged as redundant.

Actual Behavior:

Cast is flagged as redundant. Removing it introduces CS0266 on E.A in switch case.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-IDEBugIDE-CodeStyleBuilt-in analyzers, fixes, and refactoringsResolution-FixedThe bug has been fixed and/or the requested behavior has been implemented

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions