Skip to content

"Inline temporary variable" introduces an unnecessary cast that's reported as nullability issue #60552

@Tragetaschen

Description

@Tragetaschen

Version Used:
17.2.0 Preview 2.0

Steps to Reproduce:

public class C
{
    private struct S
    {
    }

    public string M()
    {
        S s;
        var a = "" + s; // "Inline temporary variable" for a
        return a;
    }
}

Run "Inline temporary variable" for a.

Expected Behavior:

public class C
{
    private struct S
    {
    }

    public string M()
    {
        S s;
        // "Inline temporary variable" for a
        return "" + s;
    }
}

Actual Behavior:

public class C
{
    private struct S
    {
    }

    public string M()
    {
        S s;
        // "Inline temporary variable" for a
        return (string?)("" + s);
    }
}

The refactoring introduces a cast to (string?) even though neither a nor the return type were ever nullable.

On a related note: Is the comment trivia expected to stay where it is and not move to the return line?

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    No type

    Projects

    Status

    Completed

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions