Skip to content

IDE0090 incorrectly suggested for new expression #50735

@JakenVeina

Description

@JakenVeina

Version Used:

Microsoft.CodeAnalysis.CSharp.NetAnalyzers 5.0.102
Microsoft.CodeAnalysis.NetAnalyzers 5.0.102

Steps to Reproduce:

Write the following code:

public static class StructExtensions
{
    public static T? ToNullable<T>(this T value)
            where T : struct
        => new T?(value);
}

Expected Behavior:

Code fixes offered should be for correct code.

Actual Behavior:

Roslyn suggests "IDE0090: 'new' expression can be simplified" on the new T?(value) expression in the above code snippet. It suggests the code fix new(value). However, applying this change results in an error, "CS0417: 'T': cannot provide arguments when created an instance of a variable type".

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