dotnet / dotnet/roslyn

Formatter doesn't increase ident in multiline list patterns correctly

Open
#73,251 1 comment 1 reaction 0 assignees View on GitHub
Area-IDE Bug help wanted
Dominant language
C#
Stars
20.7k
Forks
4.3k
PR merge metrics
PR metrics pending

Description

Found while working on a compiler PR ([link](https://github.com/dotnet/roslyn/pull/73102#discussion_r1579996363))

**Version Used**:
VS 17.10.0 Preview 5.0

**Steps to Reproduce**:
Run formatter on this code:
```cs
MyClass[] arr = [new()];

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

}

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

public int AnotherProp { get; set; }
}
```

**Expected Behavior**:
```cs
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](https://github.com/dotnet/roslyn/assets/70431552/ebd09de0-797a-4f46-b37e-8f452d9f40d0)

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the formatter behavior with the C# snippet in the issue, comparing the actual indentation with the expected output. Trace the formatter behavior for multiline list patterns; done means formatting produces the expected indentation and preserves already-correct code.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.