Skip to content

Incorrect 'IDE0004' warning (unnecessary cast), code fails if fixed #79180

Closed
@Sergio0694

Description

@Sergio0694

Version Used:

  • '4.14.0-3.25279.5 (995f12b)'. Language version: preview.
  • Latest IntPreview as well (not sharing version number here)

Steps to Reproduce:

class C
{
    public static readonly uint Foo = Bar ? (uint)Flag : 0;

    private static bool Bar => true;

    private const int Flag = 1;
}

Diagnostic Id: IDE0004

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:

No warning. The cast is needed.

Actual Behavior:

IDE0004 warning on the cast. If you apply the fix to remove it, the code fails to compile:

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-IDEhelp wantedThe issue is "up for grabs" - add a comment if you are interested in working on it

    Type

    Projects

    Status

    Completed

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions