Skip to content

Incorrect list patttern formatting #45363

Open
@MatisseHack

Description

@MatisseHack

Describe the bug

dotnet format removes indentation before list patterns in switch expressions

To Reproduce

Create a new console project with the following code:

Console.WriteLine(args switch
{
    [] => "empty",
    _ => "not empty"
});

Observe the following error:

$ dotnet format --verify-no-changes
/Users/matissehack/Desktop/format/Program.cs(3,1): error WHITESPACE: Fix whitespace formatting. Delete 4 characters. [/Users/matissehack/Desktop/format/format.csproj]

Exceptions (if any)

N/A

Further technical details

$ dotnet --info
.NET SDK:
 Version:           9.0.101
 Commit:            eedb237549
 Workload version:  9.0.100-manifests.4a280210
 MSBuild version:   17.12.12+1cce77968

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  15.1
 OS Platform: Darwin
 RID:         osx-arm64
 Base Path:   /usr/local/share/dotnet/sdk/9.0.101/

.NET workloads installed:
There are no installed workloads to display.
Configured to use loose manifests when installing new manifests.

Host:
  Version:      9.0.0
  Architecture: arm64
  Commit:       9d5a6a9aa4

.NET SDKs installed:
  9.0.101 [/usr/local/share/dotnet/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 9.0.0 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 9.0.0 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

Other architectures found:
  None

Environment variables:
  Not set

global.json file:
  Not found

Learn more:
  https://aka.ms/dotnet/info

Download .NET:
  https://aka.ms/dotnet/download

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions