RFR: 5038439: Warning message for literal shift amounts outside the canonical domain [v2]

Archie Cobbs acobbs at openjdk.org
Mon Nov 3 18:56:27 UTC 2025


On Mon, 3 Nov 2025 18:30:22 GMT, Hannes Greule <hgreule at openjdk.org> wrote:

>> Archie Cobbs has updated the pull request with a new target base due to a merge or a rebase. The pull request now contains 10 commits:
>> 
>>  - Merge branch 'master' into JDK-5038439 to fix conflict.
>>  - Address review comment (combine switch cases).
>>  - Merge branch 'master' into JDK-5038439 to fix conflict.
>>  - Add "long" as a supported message parameter type.
>>  - Use "bit(s)" instead of "bits" where value could be 1.
>>  - Merge branch 'master' into JDK-5038439
>>  - Sprinkle more variety into the regression test.
>>  - Minor diff cleanup.
>>  - Update "lossy-conversions" description in compiler module Javadoc.
>>  - Warn for bit shifts using an out-of-range shift amount.
>
> test/langtools/tools/javac/lint/ShiftOutOfRange.java line 18:
> 
>> 16:         a = a >>> (short)-1;
>> 17:         a <<= -1;
>> 18:         a >>= -1L;          // also generates "implicit cast from long to int in compound assignment is possibly lossy"
> 
> I'm a bit surprised by the additional warning here. The shift still operates on int, not long; i.e., unary promotion is performed for each argument rather than binary promotion https://docs.oracle.com/javase/specs/jls/se25/html/jls-15.html#jls-15.19
> 
> Should this be fixed (separately, obviously)?

I agree, this is a separate compiler glitch.

I've created [JDK-8371162](https://bugs.openjdk.org/browse/JDK-8371162).

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/27102#discussion_r2487531814


More information about the compiler-dev mailing list