From 8d247a9c59004ac95014399ead5fa175a3bd6e34 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sat, 2 Jun 2018 21:37:28 +0200 Subject: [PATCH] Fix #1156: Treat float, double and decimal < 0 as unary expressions in InsertParenthesesVisitor --- .../OutputVisitor/InsertParenthesesVisitor.cs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/ICSharpCode.Decompiler/CSharp/OutputVisitor/InsertParenthesesVisitor.cs b/ICSharpCode.Decompiler/CSharp/OutputVisitor/InsertParenthesesVisitor.cs index 7d2345283..701e5b9c1 100644 --- a/ICSharpCode.Decompiler/CSharp/OutputVisitor/InsertParenthesesVisitor.cs +++ b/ICSharpCode.Decompiler/CSharp/OutputVisitor/InsertParenthesesVisitor.cs @@ -70,11 +70,17 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor } if (expr is CastExpression) return Unary; - if (expr is PrimitiveExpression) { - var value = ((PrimitiveExpression)expr).Value; - if (value is int && (int)value < 0) + if (expr is PrimitiveExpression primitive) { + var value = primitive.Value; + if (value is int i && i < 0) 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; } BinaryOperatorExpression boe = expr as BinaryOperatorExpression;