Browse Source

Fix #1156: Treat float, double and decimal < 0 as unary expressions in InsertParenthesesVisitor

pull/1167/head
Siegfried Pammer 7 years ago
parent
commit
8d247a9c59
  1. 14
      ICSharpCode.Decompiler/CSharp/OutputVisitor/InsertParenthesesVisitor.cs

14
ICSharpCode.Decompiler/CSharp/OutputVisitor/InsertParenthesesVisitor.cs

@ -70,11 +70,17 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
} }
if (expr is CastExpression) if (expr is CastExpression)
return Unary; return Unary;
if (expr is PrimitiveExpression) { if (expr is PrimitiveExpression primitive) {
var value = ((PrimitiveExpression)expr).Value; var value = primitive.Value;
if (value is int && (int)value < 0) if (value is int i && i < 0)
return Unary; return Unary;
if (value is long && (long)value < 0) if (value is long l && l < 0)
return Unary;
if (value is float f && f < 0)
return Unary;
if (value is double d && d < 0)
return Unary;
if (value is decimal de && de < 0)
return Unary; return Unary;
} }
BinaryOperatorExpression boe = expr as BinaryOperatorExpression; BinaryOperatorExpression boe = expr as BinaryOperatorExpression;

Loading…
Cancel
Save