未验证 提交 f74d449c 编写于 作者: C CyrusNajmabadi 提交者: GitHub

Merge pull request #44661 from Youssef1313/patch-2

Fix wrong reporting for removing parenthesis for stackalloc
......@@ -81,6 +81,20 @@ void M()
}", new TestParameters(options: RequireArithmeticBinaryParenthesesForClarity));
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsRemoveUnnecessaryParentheses)]
[WorkItem(44629, "https://github.com/dotnet/roslyn/issues/44629")]
public async Task TestStackAlloc()
{
await TestMissingAsync(
@"class C
{
void M()
{
var span = $$(stackalloc byte[8]);
}
}");
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsRemoveUnnecessaryParentheses)]
public async Task TestArithmeticRequiredForClarity2()
{
......
......@@ -57,6 +57,17 @@ public static bool CanRemoveParentheses(this ParenthesizedExpressionSyntax node,
return true;
}
if (expression is StackAllocArrayCreationExpressionSyntax ||
expression is ImplicitStackAllocArrayCreationExpressionSyntax)
{
// var span = (stackalloc byte[8]);
// https://github.com/dotnet/roslyn/issues/44629
// The code semantics changes if the parenthesis removed.
// With parenthesis: variable span is of type `Span<byte>`.
// Without parenthesis: variable span is of type `byte*` which can only be used in unsafe context.
return false;
}
// (throw ...) -> throw ...
if (expression.IsKind(SyntaxKind.ThrowExpression))
return true;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册