Skip to content

SA1513 fires with big patterns in C# switch expression #3320

Open
@NiccoMlt

Description

@NiccoMlt

I need to pattern match an object inside a C# 8.0+ switch expression;

When the pattern is really big (ie. because of a lot of fields or long names), like the following:

public static int DummyMethodUsingSwitch(object foo) =>
    foo switch 
    {
        { Foo: { Bar: "foo bar", Baz: true }, Supercalifragilisticexpialidocious: { Something: int smth, SomethingElse: int smthElse } } => smth + smthElse,
    };

I tried formatting like this:

public static int DummyMethodUsingSwitch(object foo) =>
    foo switch 
    {
        { 
            Foo: { Bar: "foo bar", Baz: true },
            Supercalifragilisticexpialidocious: { Something: int smth, SomethingElse: int smthElse } 
        } => smth + smthElse,
    };

but SA1513 fires, suggesting the following fix:

public static int DummyMethodUsingSwitch(object foo) =>
  foo switch 
  {
     { 
        Foo: { Bar: "foo bar", Baz: true },
        Supercalifragilisticexpialidocious: { Something: int smth, SomethingElse: int smthElse } 
     } 

=> smth + smthElse,
  };

which seems inconsistently spaced.

Is it a bug or intended behavior?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions