JS: fix overflow behaviour of unary minus

This commit is contained in:
Alexey Andreev 2021-03-17 10:16:07 +03:00
parent 0064d399be
commit 02e8955abc

View File

@ -836,6 +836,18 @@ public class StatementRenderer implements ExprVisitor, StatementVisitor {
precedence = Precedence.min(); precedence = Precedence.min();
expr.getOperand().acceptVisitor(this); expr.getOperand().acceptVisitor(this);
writer.append(')'); writer.append(')');
} else if (expr.getType() == OperationType.INT) {
if (outerPrecedence.ordinal() > Precedence.BITWISE_OR.ordinal()) {
writer.append('(');
}
writer.append(" -");
precedence = Precedence.UNARY;
expr.getOperand().acceptVisitor(this);
writer.ws().append("|").ws();
writer.append("0");
if (outerPrecedence.ordinal() > Precedence.BITWISE_OR.ordinal()) {
writer.append(')');
}
} else { } else {
if (outerPrecedence.ordinal() > Precedence.UNARY.ordinal()) { if (outerPrecedence.ordinal() > Precedence.UNARY.ordinal()) {
writer.append('('); writer.append('(');