<div dir="auto">Then maybe I am not following along here.<div dir="auto"><br></div><div dir="auto">The link you sent says this.</div><div dir="auto"><br></div><div dir="auto">> a boxing conversion followed by a widening reference conversion
(<a href="https://docs.oracle.com/javase/specs/jls/se22/html/jls-5.html#jls-5.1.5">5.1.5</a>)<br></div><div dir="auto"><br></div><div dir="auto">Isn't what I described just an abbreviated version of this casting context?</div><div dir="auto"><br></div><div dir="auto">Namely, byte --> Byte --> Integer</div><div dir="auto"><br></div><div dir="auto">And even if not (I would like to know why not), my other question wasn't answered -- why not allow this?</div><div dir="auto"><br></div><div dir="auto">Specifically, I cannot imagine a single value of byte that could not be representable as Integer.</div><div dir="auto"><br></div><div dir="auto">I guess, what does this lack of ability grant us that we would lose if we made it possible? To go straight from byte to Integer, I mean.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, May 21, 2024, 5:10 AM Angelos Bimpoudis <<a href="mailto:angelos.bimpoudis@oracle.com" target="_blank" rel="noreferrer">angelos.bimpoudis@oracle.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">




<div dir="ltr">
<div style="font-family:"Segoe UI","Segoe UI Web (West European)","Helvetica Neue",sans-serif;font-size:11pt;color:rgb(0,0,0)">
The reason is that according to Casting Contexts/Section 5.5 (or Testing Contexts in JDK 23/Section 5.7 which is very similar to casting contexts) not only it is not unconditionally exact but there is no conversion at all that can support byte to Integer. If
 there were one, we would see a bullet that says: a widening primitive conversion followed by boxing. </div>
<div style="font-family:"Segoe UI","Segoe UI Web (West European)","Helvetica Neue",sans-serif;font-size:11pt;color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:"Segoe UI","Segoe UI Web (West European)","Helvetica Neue",sans-serif;font-size:11pt;color:rgb(0,0,0)">
The permitted conversions are the ones listed in Chapter 5.5 or 5.7 in the accompanying spec diff –
<a href="https://cr.openjdk.org/~abimpoudis/instanceof/jep455-20240424/specs/instanceof-jls.html#jls-5.7" rel="noreferrer noreferrer" target="_blank">
https://cr.openjdk.org/~abimpoudis/instanceof/jep455-20240424/specs/instanceof-jls.html#jls-5.7</a>.</div>
<div style="font-family:"Segoe UI","Segoe UI Web (West European)","Helvetica Neue",sans-serif;font-size:11pt;color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:"Segoe UI","Segoe UI Web (West European)","Helvetica Neue",sans-serif;font-size:11pt;color:rgb(0,0,0)">
This is also evident by trying to do the cast in JShell:</div>
<div style="font-family:"Segoe UI","Segoe UI Web (West European)","Helvetica Neue",sans-serif;font-size:11pt;color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:"Segoe UI","Segoe UI Web (West European)","Helvetica Neue",sans-serif;font-size:11pt;color:rgb(0,0,0)">
jshell> byte b = (byte) 42</div>
<div style="font-family:"Segoe UI","Segoe UI Web (West European)","Helvetica Neue",sans-serif;font-size:11pt;color:rgb(0,0,0)">
b ==> 42</div>
<div style="font-family:"Segoe UI","Segoe UI Web (West European)","Helvetica Neue",sans-serif;font-size:11pt;color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:"Segoe UI","Segoe UI Web (West European)","Helvetica Neue",sans-serif;font-size:11pt;color:rgb(0,0,0)">
jshell> (Integer) b</div>
<div style="font-family:"Segoe UI","Segoe UI Web (West European)","Helvetica Neue",sans-serif;font-size:11pt;color:rgb(0,0,0)">
|  Error:</div>
<div style="font-family:"Segoe UI","Segoe UI Web (West European)","Helvetica Neue",sans-serif;font-size:11pt;color:rgb(0,0,0)">
|  incompatible types: byte cannot be converted to java.lang.Integer</div>
<div style="font-family:"Segoe UI","Segoe UI Web (West European)","Helvetica Neue",sans-serif;font-size:11pt;color:rgb(0,0,0)">
|  (Integer) b</div>
<div style="font-family:"Segoe UI","Segoe UI Web (West European)","Helvetica Neue",sans-serif;font-size:11pt;color:rgb(0,0,0)">
|            ^</div>
<div style="font-family:"Segoe UI","Segoe UI Web (West European)","Helvetica Neue",sans-serif;font-size:11pt;color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:"Segoe UI","Segoe UI Web (West European)","Helvetica Neue",sans-serif;font-size:11pt;color:rgb(0,0,0)">
Note, that while dominance checks the relation between two case labels, those two case labels can be independently applicable to the selector type. </div>
<div id="m_7071760543876253191m_-2137656019731801328appendonsend"></div>
<hr style="display:inline-block;width:98%">
<div id="m_7071760543876253191m_-2137656019731801328divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> David Alayachew <<a href="mailto:davidalayachew@gmail.com" rel="noreferrer noreferrer" target="_blank">davidalayachew@gmail.com</a>><br>
<b>Sent:</b> 21 May 2024 00:12<br>
<b>To:</b> Aggelos Biboudis <<a href="mailto:abimpoudis@openjdk.org" rel="noreferrer noreferrer" target="_blank">abimpoudis@openjdk.org</a>><br>
<b>Cc:</b> compiler-dev <<a href="mailto:compiler-dev@openjdk.org" rel="noreferrer noreferrer" target="_blank">compiler-dev@openjdk.org</a>><br>
<b>Subject:</b> Re: RFR: 8332463: Byte conditional pattern case element dominates short constant case element</font>
<div> </div>
</div>
<div>
<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>
<div dir="ltr">On Mon, May 20, 2024, 4:31 AM Aggelos Biboudis <<a href="mailto:abimpoudis@openjdk.org" rel="noreferrer noreferrer" target="_blank">abimpoudis@openjdk.org</a>> wrote:<br>
</div>
<blockquote 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 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 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 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 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 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 noreferrer noreferrer" target="_blank">
https://git.openjdk.org/jdk/pull/19301</a><br>
</blockquote>
</div>
</div>
</div>
</div>
</div>

</blockquote></div>