dotnet/roslyn

Formatter doesn't increase ident in multiline list patterns correctly

Open

#73,251 opened on Apr 27, 2024

View on GitHub
 (1 comment) (0 reactions) (0 assignees)C# (4,257 forks)batch import
Area-IDEBughelp wanted

Repository metrics

Stars
 (20,414 stars)
PR merge metrics
 (Avg merge 6d 17h) (256 merged PRs in 30d)

Description

Found while working on a compiler PR (link)

Version Used: VS 17.10.0 Preview 5.0

Steps to Reproduce: Run formatter on this code:

MyClass[] arr = [new()];

if (arr is
    [
    {
        Prop: 1,
        AnotherProp: 2
    }
    ])
{

}

class MyClass
{
    public int Prop { get; set; }

    public int AnotherProp { get; set; }
}

Expected Behavior:

MyClass[] arr = [new()];

if (arr is
    [
        {
            Prop: 1,
            AnotherProp: 2
        }
    ])
{

}

class MyClass
{
    public int Prop { get; set; }

    public int AnotherProp { get; set; }
}

Actual Behavior: Quite the opposite - when I run formatting on correct code, it dedents it back: formatterBug

Contributor guide