未验证 提交 6c9ac78d 编写于 作者: S Sam Harwell 提交者: GitHub

Merge pull request #47372 from Youssef1313/parenthesis-bug

Fix IsSafeToChangeAssociativity for dynamic variables
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
......@@ -95,6 +95,22 @@ void M()
}");
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsRemoveUnnecessaryParentheses)]
[WorkItem(47365, "https://github.com/dotnet/roslyn/issues/47365")]
public async Task TestDynamic()
{
await TestMissingAsync(
@"class C
{
void M()
{
dynamic i = 1;
dynamic s = ""s"";
Console.WriteLine(s + $$(1 + i));
}
}");
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsRemoveUnnecessaryParentheses)]
public async Task TestArithmeticRequiredForClarity2()
{
......
......@@ -40,6 +40,12 @@ internal static class CommonParenthesizedExpressionSyntaxExtensions
}
}
// It's not safe to change associativity for dynamic variables as the actual type isn't known. See https://github.com/dotnet/roslyn/issues/47365
if (innerTypeInfo.Type is IDynamicTypeSymbol)
{
return false;
}
// Only allow us to change associativity if all the types are the same.
// for example, if we have: int + (int + long) then we don't want to
// change things such that we effectively have (int + int) + long
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册