Skip to content

Commit 0a69e86

Browse files
committed
Fix Unary Minus Constant Folding
1 parent 9ef9595 commit 0a69e86

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

liquidjava-verifier/src/main/java/liquidjava/rj_language/opt/ConstantFolding.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,17 @@ private static Expression foldUnaryExpression(UnaryExpression unaryExp) {
119119
boolean value = ((LiteralBoolean) operand).isBooleanTrue();
120120
return new LiteralBoolean(!value);
121121
}
122+
if (operator.equals("-")) {
123+
// -(x) = -x
124+
if (operand instanceof LiteralInt) {
125+
int value = ((LiteralInt) operand).getValue();
126+
return new LiteralInt(-value);
127+
}
128+
if (operand instanceof LiteralReal) {
129+
double value = ((LiteralReal) operand).getValue();
130+
return new LiteralReal(-value);
131+
}
132+
}
122133
return unaryExp;
123134
}
124135
}

0 commit comments

Comments
 (0)