<div dir="auto"><div>I understand the first 2 cases, but not the third. How is byte -> Integer not unconditionally exact? What possible scenario could occur where one would lose data?<br><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, May 20, 2024, 4:31 AM Aggelos Biboudis <<a href="mailto:abimpoudis@openjdk.org">abimpoudis@openjdk.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">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:<br>
<br>
<br>
public static int test() {<br>
    Byte i = (byte) 42;<br>
    return switch (i) {<br>
        case Byte ib   -> 1;<br>
        case (short) 0 -> 2; // OK - not dominated<br>
    };<br>
}<br>
<br>
<br>
Similarly for primitive type patterns:<br>
<br>
<br>
public static int test() {<br>
    Byte i = (byte) 42;<br>
    return switch (i) {<br>
        case Byte ib  -> 1;<br>
        case short s  -> 2; // Also not dominated since there is no unconditionally exact conversion from short to Byte<br>
    };<br>
}<br>
<br>
public static int test() {<br>
    int i = 42;<br>
    return switch (i) {<br>
        case Integer ib -> 1;<br>
        case byte ip    -> 2; // Also not dominated since there is no unconditionally exact conversion from byte to Integer<br>
    };<br>
}<br>
<br>
-------------<br>
<br>
Commit messages:<br>
 - 8332463: Byte conditional pattern case element dominates short constant case element<br>
<br>
Changes: <a href="https://git.openjdk.org/jdk/pull/19301/files" rel="noreferrer noreferrer" target="_blank">https://git.openjdk.org/jdk/pull/19301/files</a><br>
  Webrev: <a href="https://webrevs.openjdk.org/?repo=jdk&pr=19301&range=00" rel="noreferrer noreferrer" target="_blank">https://webrevs.openjdk.org/?repo=jdk&pr=19301&range=00</a><br>
  Issue: <a href="https://bugs.openjdk.org/browse/JDK-8332463" rel="noreferrer noreferrer" target="_blank">https://bugs.openjdk.org/browse/JDK-8332463</a><br>
  Stats: 104 lines in 5 files changed: 94 ins; 7 del; 3 mod<br>
  Patch: <a href="https://git.openjdk.org/jdk/pull/19301.diff" rel="noreferrer noreferrer" target="_blank">https://git.openjdk.org/jdk/pull/19301.diff</a><br>
  Fetch: git fetch <a href="https://git.openjdk.org/jdk.git" rel="noreferrer noreferrer" target="_blank">https://git.openjdk.org/jdk.git</a> pull/19301/head:pull/19301<br>
<br>
PR: <a href="https://git.openjdk.org/jdk/pull/19301" rel="noreferrer noreferrer" target="_blank">https://git.openjdk.org/jdk/pull/19301</a><br>
</blockquote></div></div></div>