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 ec5c7775b..eb87f6d67 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 @@ -755,7 +755,8 @@ public class StatementRenderer implements ExprVisitor, StatementVisitor { visitBinary(expr, ">>", false); break; case UNSIGNED_RIGHT_SHIFT: - visitBinary(expr, ">>>", false); + // JavaScript not casts -2147483648 >>> 0 to 2147483648, which is not 32 bit integer. + visitBinary(expr, ">>>", true); break; } } diff --git a/tests/src/test/java/org/teavm/classlib/java/lang/IntegerTest.java b/tests/src/test/java/org/teavm/classlib/java/lang/IntegerTest.java index 09a19b4f4..f484ede3c 100644 --- a/tests/src/test/java/org/teavm/classlib/java/lang/IntegerTest.java +++ b/tests/src/test/java/org/teavm/classlib/java/lang/IntegerTest.java @@ -180,4 +180,9 @@ public class IntegerTest { assertEquals("1111111111111111111111111111111", Integer.toString(Integer.MAX_VALUE, 2)); assertEquals("-10000000000000000000000000000000", Integer.toString(Integer.MIN_VALUE, 2)); } + + @Test + public void unsignedRightShift() { + assertEquals(Integer.MIN_VALUE, Integer.MIN_VALUE >>> Integer.parseInt("0")); + } }