Skip to content

"IDE0004 C# Cast is redundant" is reported incorrectly for default #49954

@abatishchev

Description

@abatishchev

Version Used:

I'm sorry for dumb question but how to tell?

Environment:

VisualStudio.16.Release/16.8.3+30804.86

Steps to Reproduce:

protected bool? IsNewResource() =>
    Boolean.TryParse(GetHeader(HttpHeaders.NewResource), out var b) ? b : (bool?)default; 

Expected Behavior:

No issue is reported.

Actual Behavior:

Modified code:

protected bool? IsNewResource() =>
    Boolean.TryParse(GetHeader(HttpHeaders.NewResource), out var b) ? b : default as bool?;

doesn't compile:

CS8716 There is no target type for the default literal.

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