未验证 提交 5191bfdc 编写于 作者: S Sam Harwell 提交者: GitHub

Merge pull request #29800 from sharwell/missing-parens

Do not remove parentheses from incomplete expressions
......@@ -44,6 +44,20 @@ void M()
}", new TestParameters(options: IgnoreAllParentheses));
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsRemoveUnnecessaryParentheses)]
[WorkItem(29736, "https://github.com/dotnet/roslyn/issues/29736")]
public async Task TestVariableInitializer_TestMissingParenthesis()
{
await TestMissingAsync(
@"class C
{
void M()
{
int x = $$(1;
}
}");
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsRemoveUnnecessaryParentheses)]
public async Task TestArithmeticRequiredForClarity1()
{
......
......@@ -38,6 +38,17 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.RemoveUnnecessaryP
end class", New TestParameters(options:=IgnoreAllParentheses))
End Function
<Fact, Trait(Traits.Feature, Traits.Features.CodeActionsRemoveUnnecessaryParentheses)>
<WorkItem(29736, "https://github.com/dotnet/roslyn/issues/29736")>
Public Async Function TestVariableInitializer_MissingParenthesis() As Task
Await TestMissingAsync(
"class C
sub M()
dim x = $$(1
end sub
end class")
End Function
<Fact, Trait(Traits.Feature, Traits.Features.CodeActionsRemoveUnnecessaryParentheses)>
Public Async Function TestArithmeticRequiredForClarity1() As Task
Await TestMissingAsync(
......
......@@ -14,6 +14,12 @@ internal static class ParenthesizedExpressionSyntaxExtensions
{
public static bool CanRemoveParentheses(this ParenthesizedExpressionSyntax node, SemanticModel semanticModel)
{
if (node.OpenParenToken.IsMissing || node.CloseParenToken.IsMissing)
{
// int x = (3;
return false;
}
var expression = node.Expression;
// The 'direct' expression that contains this parenthesized node. Note: in the case
......
......@@ -42,6 +42,12 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Extensions
Optional cancellationToken As CancellationToken = Nothing
) As Boolean
If node.OpenParenToken.IsMissing OrElse node.CloseParenToken.IsMissing Then
' Cases:
' (3
Return False
End If
Dim expression = node.Expression
' Cases:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册