Skip to content

Commit

Permalink
Preserve trailing trivia on open brace (#53412)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidwengier authored May 14, 2021
1 parent fa5a5bb commit 1357a6f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ private ExpressionSyntax RewriteSwitchStatement(SwitchStatementSyntax node, Sema
return SwitchExpression(
switchStatement.Expression.Parenthesize(),
Token(leading: default, SyntaxKind.SwitchKeyword, node.CloseParenToken.TrailingTrivia),
Token(SyntaxKind.OpenBraceToken),
Token(leading: default, SyntaxKind.OpenBraceToken, node.OpenBraceToken.TrailingTrivia),
SeparatedList(
switchArms.Select(t => t.armExpression.WithLeadingTrivia(t.tokensForLeadingTrivia.GetTrivia().FilterComments(addElasticMarker: false))),
switchArms.Select(t => Token(SyntaxKind.CommaToken).WithTrailingTrivia(t.tokensForTrailingTrivia.GetTrivia().FilterComments(addElasticMarker: true)))),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,37 @@ static int GetValue(int input)
}");
}

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsConvertSwitchStatementToExpression)]
[WorkItem(52258, "https://github.com/dotnet/roslyn/issues/52258")]
public async Task TestTrivia_03()
{
await VerifyCS.VerifyCodeFixAsync(
@"class Program
{
int M(int i)
{
[|switch|] (i)
{ // Tip-toe through the trailing trivia
case 0: return 123;
case 1: return 234;
default: throw null;
}
}
}",
@"class Program
{
int M(int i)
{
return i switch
{ // Tip-toe through the trailing trivia
0 => 123,
1 => 234,
_ => throw null,
};
}
}");
}

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsConvertSwitchStatementToExpression)]
[WorkItem(36086, "https://github.com/dotnet/roslyn/issues/36086")]
public async Task TestSeverity()
Expand Down

0 comments on commit 1357a6f

Please sign in to comment.