Skip to content

Unnecessary cast added to the default arm in the IDE0066 fixer #77084

@RenderMichael

Description

@RenderMichael

Version Used:

Steps to Reproduce:

class Program
{
    public object M(int i, string j)
    {
        switch (i, j)
        {
            case (0, _):
                return true;

            case (_, null):
                return true;

            default:
                return false;
        }
    }
}

Diagnostic Id:

"IDE0066: Use 'switch' expression"

Expected Behavior:

class Program
{
    bool M(int i, string j)
    {
        return (i, j) switch
        {
            (0, _) => true,
            (_, null) => true,
            _ => false,
        };
    }
}

Actual Behavior:

class Program
{
    public object M(int i, string j)
    {
        return (i, j)
switch
        {
            (0, _) => true,
            (_, null) => true,
            _ => (object)false,
        };
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-IDEBugFeature - IDE0066Convert switch statement to expressionhelp wantedThe issue is "up for grabs" - add a comment if you are interested in working on it

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions