Skip to content

Incorrect "Cast is redundant" for constant patterns where the constant is an explicit cast from a numeric literal #45925

@jnm2

Description

@jnm2

Version Used: 16.7-p3.1

There should be no diagnostics here. Any change results in different runtime behavior.

_ denotes a faded span.

class C
{
    bool M(object obj)
    {
        // IDE0004: Cast is redundant
        //                 ______     ______     _______     _______     ________     ______     _______
        return obj is 0 or (uint)0 or (long)0 or (ulong)0 or (short)0 or (ushort)0 or (byte)0 or (sbyte)0 or (float)0
        //      ________     _________     __________________
             or (double)0 or (decimal)0 or (AttributeTargets)0;
    }
}

(All but short, ushort, byte, and sbyte would normally be written using numeric literal suffixes rather than explicit casts.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-IDEBugIDE-CodeStyleBuilt-in analyzers, fixes, and refactoringshelp wantedThe issue is "up for grabs" - add a comment if you are interested in working on it

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions