diff options
author | Siegfried Pammer <siegfriedpammer@gmail.com> | 2016-07-23 17:08:50 +0300 |
---|---|---|
committer | Siegfried Pammer <siegfriedpammer@gmail.com> | 2016-07-23 17:08:50 +0300 |
commit | 19497cfae13c3dcebed7dfeb1cba549e4c2deded (patch) | |
tree | 06b59a44ff913d7b8467d2030d02b10b506f810c | |
parent | 0254d4899eb45422ecca76fdb41c356976f720d5 (diff) |
InsertParenthesesVisitor: Add parentheses to PrimitiveExpression if its value is a negative int/long. -1.ToString() is interpreted as -(1.ToString()) by the parser. We need parentheses in order to fix this.
-rw-r--r-- | ICSharpCode.NRefactory.CSharp/OutputVisitor/InsertParenthesesVisitor.cs | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/ICSharpCode.NRefactory.CSharp/OutputVisitor/InsertParenthesesVisitor.cs b/ICSharpCode.NRefactory.CSharp/OutputVisitor/InsertParenthesesVisitor.cs index 4528a5f9..475ca40b 100644 --- a/ICSharpCode.NRefactory.CSharp/OutputVisitor/InsertParenthesesVisitor.cs +++ b/ICSharpCode.NRefactory.CSharp/OutputVisitor/InsertParenthesesVisitor.cs @@ -63,6 +63,13 @@ namespace ICSharpCode.NRefactory.CSharp } if (expr is CastExpression) return Unary; + if (expr is PrimitiveExpression) { + var value = ((PrimitiveExpression)expr).Value; + if (value is int && (int)value < 0) + return Unary; + if (value is long && (long)value < 0) + return Unary; + } BinaryOperatorExpression boe = expr as BinaryOperatorExpression; if (boe != null) { switch (boe.Operator) { |