Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve trailing trivia on open brace #53412

Merged
merged 1 commit into from
May 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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