classlib: fix issue with integer unsigned right shift

This commit is contained in:
Alexey Andreev 2023-05-16 09:56:24 +02:00
parent 9f349385ec
commit c39efdc6d7
2 changed files with 7 additions and 1 deletions

View File

@ -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;
}
}

View File

@ -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"));
}
}