Skip to content

"Use coalesce expression" loses comments between variable declaration and if statement #82060

@jhinder

Description

@jhinder

Follow-up to #82037, which I can't reopen for some reason.

Version Used: Local build of latest main revision, da6cf36, i.e. already containing the fix #82041.

Steps to Reproduce:
Invoke "Use coalesce expression" on the if statement.

class D
{
    public void M()
    {
        var value = M2();
        // Test
        if (value == null)
        {
            throw new InvalidOperationException();
        }
    }

    string? M2() => null;
}

Expected Behavior: The comment is placed before or after the rewritten statement.

Actual Behavior: The comment is dropped.

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions