From 02e8955abcf3eba7dedf133b4036082c48307b90 Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Wed, 17 Mar 2021 10:16:07 +0300 Subject: [PATCH] JS: fix overflow behaviour of unary minus --- .../javascript/rendering/StatementRenderer.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/core/src/main/java/org/teavm/backend/javascript/rendering/StatementRenderer.java b/core/src/main/java/org/teavm/backend/javascript/rendering/StatementRenderer.java index 5ba1684ee..9e9ba4c42 100644 --- a/core/src/main/java/org/teavm/backend/javascript/rendering/StatementRenderer.java +++ b/core/src/main/java/org/teavm/backend/javascript/rendering/StatementRenderer.java @@ -836,6 +836,18 @@ public class StatementRenderer implements ExprVisitor, StatementVisitor { precedence = Precedence.min(); expr.getOperand().acceptVisitor(this); 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 { if (outerPrecedence.ordinal() > Precedence.UNARY.ordinal()) { writer.append('(');