Skip to content

"Use coalesce expression" drops trivia #82037

@jhinder

Description

@jhinder

Version Used: VS 18.2.0

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

class C
{
    public void M()
    {
#pragma warning disable
        var value = M2();
        // Test
#pragma warning restore
        if (value == null)
        {
            throw new InvalidOperationException();
        }
    }

    string? M2() => null;
}

Expected Behavior: The trivia (comment, directive) is retained and placed after the rewritten statement.

Actual Behavior: The trivia is dropped entirely.

Image

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions