提交 899f42bf 编写于 作者: V Victor Zaytsev 提交者: Heejae Chang

Incorrect IDE0004 "Cast is redundant" when passing enum cast to int as...

Incorrect IDE0004 "Cast is redundant" when passing enum cast to int as constructor parameter accepting int (#32467)

* Fixed 31963

* Added tests.
上级 ac975d0a
......@@ -4605,6 +4605,69 @@ public void Test()
var a = new Apple();
([|(Fruit)a|]).Properties[""Color""] = ""Red"";
}
}");
}
[WorkItem(31963, "https://github.com/dotnet/roslyn/issues/31963")]
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsRemoveUnnecessaryCast)]
public async Task DontOfferToRemoveCastInConstructorWhenItNeeded()
{
await TestMissingInRegularAndScriptAsync(@"
class IntegerWrapper
{
public IntegerWrapper(int value)
{
}
}
enum Goo
{
First,
Second
}
class Tester
{
public void Test()
{
var a = new IntegerWrapper([|(int)Goo.First|]);
}
}");
}
[WorkItem(31963, "https://github.com/dotnet/roslyn/issues/31963")]
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsRemoveUnnecessaryCast)]
public async Task DontOfferToRemoveCastInBaseConstructorInitializerWhenItNeeded()
{
await TestMissingInRegularAndScriptAsync(
@"
class B
{
B(int a)
{
}
}
class C : B
{
C(double a) : base([|(int)a|])
{
}
}");
}
[WorkItem(31963, "https://github.com/dotnet/roslyn/issues/31963")]
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsRemoveUnnecessaryCast)]
public async Task DontOfferToRemoveCastInConstructorInitializerWhenItNeeded()
{
await TestMissingInRegularAndScriptAsync(
@"
class B
{
B(int a)
{
}
B(double a) : this([|(int)a|])
{
}
}");
}
}
......
......@@ -510,10 +510,12 @@ private bool ReplacementBreaksCollectionInitializerAddMethod(ExpressionSyntax or
protected override bool ExpressionMightReferenceMember(SyntaxNode node)
{
return node.IsKind(SyntaxKind.InvocationExpression) ||
node.IsKind(SyntaxKind.ElementAccessExpression) ||
node.IsKind(SyntaxKind.SimpleMemberAccessExpression) ||
node.IsKind(SyntaxKind.ImplicitElementAccess);
return node.IsKind(
SyntaxKind.InvocationExpression,
SyntaxKind.ElementAccessExpression,
SyntaxKind.SimpleMemberAccessExpression,
SyntaxKind.ImplicitElementAccess,
SyntaxKind.ObjectCreationExpression);
}
protected override ImmutableArray<ArgumentSyntax> GetArguments(ExpressionSyntax expression)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册