New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug fix for issue #8111 - Don't mark cast as redundant if removing it will change the shape of a new anonymous object #8195
Conversation
… will change the shape of a new anonymous object This fixes a corner case in which the IDE0004 diagnostic ("C# Cast is redundant") claims a cast is safe to remove, when removing it could in fact change program behavior, by changing the type of an anonymous object's member
@dotnet-bot test eta please tag @dotnet/roslyn-ide @DustinCampbell |
@dotnet-bot retest prtest/mac/dbg/unit32 please |
public enum Directions { North, East, South, West } | ||
} | ||
"); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's be good to add a test to ensure that it still reports redundant identity casts in this scenario.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, tests for casts when the property name is omitted. E.g.
object thing = new { (int)Directions.South };
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both good ideas, I'll try to get those in soon
Ignore my comment about |
…nAnalyzer (from CastExpressionSyntaxExtentions)
…dundant from being marked for removal
tag @dotnet/roslyn-ide for another look. |
LGTM |
@@ -430,10 +430,23 @@ protected override bool ReplacementChangesSemanticsForNodeLanguageSpecific(Synta | |||
{ | |||
return !TypesAreCompatible((ImplicitArrayCreationExpressionSyntax)currentOriginalNode, (ImplicitArrayCreationExpressionSyntax)currentReplacedNode); | |||
} | |||
else if (currentOriginalNode is AnonymousObjectMemberDeclaratorSyntax) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why 'is' instead of the Kind checks like above?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Saw others with "is", especially at the top of the method, copied that style.
|
Sorry for the late reply on this, we'll try and get this merged in today. @dotnet-bot test eta please |
@dotnet-bot test eta please |
@dotnet-bot test eta please |
test vsi please |
retest this please |
@steveniles -- sorry it took so long to get this one in. Running tests one more time. |
@DustinCampbell No problem, figured it would get done once the issues with the test server(s) were resolved :) |
Fixes #8111
This fixes a corner case in which the IDE0004 diagnostic ("C# Cast is redundant") claims a cast is safe to remove, when removing it could in fact change program behavior, by changing the type of an anonymous object's member