RFR: 8332463: Byte conditional pattern case element dominates short constant case element

Aggelos Biboudis abimpoudis at openjdk.org
Mon May 20 08:30:32 UTC 2024


It seems that the compiler introduced a rule that does not exist in the spec. The fix is simple, and it will fix the behaviour of JDK 23 according to the spec. For example the following is accepted by JDK 22 and needs to continue to be accepted by JDK 23:


public static int test() {
    Byte i = (byte) 42;
    return switch (i) {
        case Byte ib   -> 1;
        case (short) 0 -> 2; // OK - not dominated
    };
}


Similarly for primitive type patterns:


public static int test() {
    Byte i = (byte) 42;
    return switch (i) {
        case Byte ib  -> 1;
        case short s  -> 2; // Also not dominated since there is no unconditionally exact conversion from short to Byte
    };
}

public static int test() {
    int i = 42;
    return switch (i) {
        case Integer ib -> 1;
        case byte ip    -> 2; // Also not dominated since there is no unconditionally exact conversion from byte to Integer
    };
}

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

Commit messages:
 - 8332463: Byte conditional pattern case element dominates short constant case element

Changes: https://git.openjdk.org/jdk/pull/19301/files
  Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=19301&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8332463
  Stats: 104 lines in 5 files changed: 94 ins; 7 del; 3 mod
  Patch: https://git.openjdk.org/jdk/pull/19301.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/19301/head:pull/19301

PR: https://git.openjdk.org/jdk/pull/19301


More information about the compiler-dev mailing list