eclipse-archived/ceylon

Java runtime: Integer span overflow/wraparound

Opened this issue · 1 comments

dlkw commented
print(1.leftLogicalShift(31)- 5); // ok, 2147483643
print(1.leftLogicalShift(31) + 5); // ok, 2147483653
print((1.leftLogicalShift(31)-5)..(1.leftLogicalShift(31)+5)); // ok, 2147483643..2147483653

for (i in (1.leftLogicalShift(31)-5)..(1.leftLogicalShift(31)+5)) {
    print(i); // OUCH! counts from 2147483643 downwards without end
}

This is a compiler bug with the optimize for loop having:

        final long $ceylontmp$first$2 = (1 << 31L) - 5;
        final long $ceylontmp$last$3 = (1 << 31L) + 5;

where the 1s should be 1Ls.