Skip to content

Incorrect IDE0004 'Cast is redundant' on switch expression #42657

@jnm2

Description

@jnm2

Version Used: VS 16.6-p1

There should be no prompt to remove the enum cast. Removing it would change the exception message.

_ indicates faded text:

class C
{
    object M(int rawKind)
    {
        // ℹ IDE0004 Cast is redundant
        //     ____________
        return (SyntaxKind)rawKind switch
        {
            var kind => throw new NotImplementedException(kind.ToString()),
        };
    }
}

Metadata

Metadata

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