Skip to content

Commit 96b3488

Browse files
authored
Handle weird edge case with switch expression inside parenthesized expression followed by a long invocation chain (#1549)
closes #1546
1 parent 9ae7bf1 commit 96b3488

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

Src/CSharpier.Tests/FormattingTests/TestFiles/cs/SwitchExpressions.test

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,5 +119,16 @@ class ClassName
119119
"someLongString________________________________________________________________"
120120
),
121121
};
122+
123+
(
124+
someValue switch
125+
{
126+
someValue => 1,
127+
_ => 2,
128+
}
129+
)
130+
.SomeLongMethodCall______________________________()
131+
.SomeLongMethodCall______________________________()
132+
.SomeLongMethodCall______________________________();
122133
}
123134
}

Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/InvocationExpression.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ is LiteralExpressionSyntax
106106
is ArrayCreationExpressionSyntax
107107
or ObjectCreationExpressionSyntax { Initializer: not null }
108108
)
109+
|| groups[0].First().Node
110+
is ParenthesizedExpressionSyntax { Expression: SwitchExpressionSyntax }
109111
? expanded
110112
: Doc.ConditionalGroup(Doc.Concat(oneLine), expanded);
111113
}

0 commit comments

Comments
 (0)