提交 09fa9eaf 编写于 作者: M meziantou

IDE0066 code fix adds parentheses when needed

上级 8157ef8f
......@@ -661,5 +661,42 @@ int M(int i)
Assert.Equal(DiagnosticSeverity.Warning, diag.Severity);
Assert.Equal(IDEDiagnosticIds.ConvertSwitchStatementToExpressionDiagnosticId, diag.Id);
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsConvertSwitchStatementToExpression)]
[WorkItem(36995, "https://github.com/dotnet/roslyn/issues/36995")]
public async Task TestAddParenthesesAroundBinaryExpression()
{
await TestInCSharp8(
@"class Program
{
void M(int i)
{
int j = 123;
[||]switch (i % 10)
{
case 1:
j = 4;
break;
case 2:
j = 5;
break;
}
throw null;
}
}",
@"class Program
{
void M(int i)
{
int j = 123;
j = (i % 10) switch
{
1 => 4,
2 => 5,
_ => throw null,
};
}
}");
}
}
}
......@@ -245,7 +245,7 @@ private ExpressionSyntax RewriteSwitchStatement(SwitchStatementSyntax node, bool
}
return SwitchExpression(
node.Expression,
node.Expression.Parenthesize(),
Token(leading: default, SyntaxKind.SwitchKeyword, node.CloseParenToken.TrailingTrivia),
Token(SyntaxKind.OpenBraceToken),
SeparatedList(
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册