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

Jan Lahoda jlahoda at openjdk.org
Wed Nov 5 15:07:34 UTC 2025


On Mon, 3 Nov 2025 18:31:48 GMT, Archie Cobbs <acobbs at openjdk.org> wrote:

>> src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java line 4055:
>> 
>>> 4053:             int maximumShift;
>>> 4054:             switch (((OperatorSymbol)operator).opcode) {
>>> 4055:             case ByteCodes.ishl:
>> 
>> Nit: use "modernized" switch - multiple case labels and `->`?
>
> We can combined the labels, but since we're setting _two_ values we can't use the `->` syntax. Fixed in 8044632727d.

Having two assignments should not be a blocker for `->`, no? It ought to be enough to use `{}`:

            switch (((OperatorSymbol)operator).opcode) {
            case ByteCodes.ishl, ByteCodes.ishr, ByteCodes.iushr,
                 ByteCodes.ishll, ByteCodes.ishrl, ByteCodes.iushrl -> {
                targetType = syms.intType;
                maximumShift = 32;
            }
            case ByteCodes.lshl, ByteCodes.lshr, ByteCodes.lushr,
                 ByteCodes.lshll, ByteCodes.lshrl, ByteCodes.lushrl -> {
                targetType = syms.longType;
                maximumShift = 64;
            }
            default -> {
                return;
            }
            }


I am not strictly insisting on using `->`, but it generally makes things simpler as there's guaranteed no fallthrough.

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

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


More information about the build-dev mailing list