Skip to content
This repository has been archived by the owner on Sep 24, 2020. It is now read-only.

Commit

Permalink
Even in readability mode, don't parenthesize casts of casts
Browse files Browse the repository at this point in the history
  • Loading branch information
dgrunwald committed Jul 9, 2016
1 parent 96c2f37 commit 0254d48
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,10 @@ public override void VisitUnaryOperatorExpression(UnaryOperatorExpression unaryO

public override void VisitCastExpression(CastExpression castExpression)
{
ParenthesizeIfRequired(castExpression.Expression, InsertParenthesesForReadability ? Primary : Unary);
// Even in readability mode, don't parenthesize casts of casts.
if (!(castExpression.Expression is CastExpression)) {
ParenthesizeIfRequired(castExpression.Expression, InsertParenthesesForReadability ? Primary : Unary);
}
// There's a nasty issue in the C# grammar: cast expressions including certain operators are ambiguous in some cases
// "(int)-1" is fine, but "(A)-b" is not a cast.
UnaryOperatorExpression uoe = castExpression.Expression as UnaryOperatorExpression;
Expand Down

0 comments on commit 0254d48

Please sign in to comment.