<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Sep 13, 2022 at 10:08 AM <<a href="mailto:forax@univ-mlv.fr">forax@univ-mlv.fr</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><div style="font-family:arial,helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)"><div><br></div><div><br></div><hr id="m_-6531037436117230409zwchr"><div><blockquote style="border-left:2px solid rgb(16,16,255);margin-left:5px;padding-left:5px;color:rgb(0,0,0);font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt"><b>From: </b>"John Rose" <<a href="mailto:john.r.rose@oracle.com" target="_blank">john.r.rose@oracle.com</a>><br><b>To: </b>"Remi Forax" <<a href="mailto:forax@univ-mlv.fr" target="_blank">forax@univ-mlv.fr</a>><br><b>Cc: </b>"Brian Goetz" <<a href="mailto:brian.goetz@oracle.com" target="_blank">brian.goetz@oracle.com</a>>, "amber-spec-experts" <<a href="mailto:amber-spec-experts@openjdk.java.net" target="_blank">amber-spec-experts@openjdk.java.net</a>><br><b>Sent: </b>Tuesday, September 13, 2022 12:58:47 AM<br><b>Subject: </b>Re: Knocking off two more vestiges of legacy switch<br></blockquote></div><div><blockquote style="border-left:2px solid rgb(16,16,255);margin-left:5px;padding-left:5px;color:rgb(0,0,0);font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt"><div style="font-family:sans-serif"><div style="white-space:normal">
<p dir="auto">It’s too harsh to say your example shows the semantics are just wrong.</p></div></div></blockquote><div><br></div><div>yes, it's more than there is inconsistencies<br></div><div><br></div><blockquote style="border-left:2px solid rgb(16,16,255);margin-left:5px;padding-left:5px;color:rgb(0,0,0);font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt"><div style="font-family:sans-serif"><div style="white-space:normal">
<p dir="auto">I think they are right, but possibly incomplete. The exclusion of case 200 is the job of dead code detection logic in the language, the same kind of logic that also reports an error on <code style="margin:0px;padding:0px 0.4em;border-radius:3px;background-color:rgb(247,247,247)">"foo" instanceof List</code>.</p>
<p dir="auto">Then there are the old murky rules that allow an integral constant like 100 to assign to <code style="margin:0px;padding:0px 0.4em;border-radius:3px;background-color:rgb(247,247,247)">byte</code> only because 100 fits in the byte range while 200 does not. The duals of those rules will surely speak to the restriction of <code style="margin:0px;padding:0px 0.4em;border-radius:3px;background-color:rgb(247,247,247)">case 200:</code> matching a byte.</p></div></div></blockquote><div><br></div><div>The problem with that approach is that the semantics of constant patterns and the semantics of primitive type patterns will be not aligned,<br></div><div>so if you have both pattern in a switch, users will spot the inconsistency.<br></div><div><br></div><div>something like<br></div><div> byte b = ...<br></div><div> switch(b) {<br></div><div> case 200 -> ... // does not compile, incompatible types between byte and int<br></div><div> case int i -> ... // ok, compiles<br></div><div> }<br></div></div></div></div></blockquote><div><br></div><div>I've been following along on this discussion and I'm not sure what the inconsistency here is. Remi, can you clarify? </div><div><br></div><div>As a developer, the semantics here are intuitive - I can't have a (signed) byte that matches 200 so as John said earlier, it's clearly dead code. On the other hand, bytes can always be converted to an int so it makes sense that the `case int i` both compiles and matches to the byte. Can you expand on why users would find that confusing?</div><div><br></div><div>--Dan</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><div style="font-family:arial,helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)"><div><div></div><div><br></div><div>So i agree that we should have primitive type patterns but instead of using the casting rules as model, the actual rules complemented with boolean, long, float and double seems a better fit.<br></div><div><br></div><div>Compared to what Brian proposed, it means all primitive patterns are unconditional apart unboxing if the pattern is not total (the same way reference type pattern works with null).<br></div><div><br></div><div>Rémi<br></div><div><br></div><blockquote style="border-left:2px solid rgb(16,16,255);margin-left:5px;padding-left:5px;color:rgb(0,0,0);font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt"><div style="font-family:sans-serif"><div style="white-space:normal">
<p dir="auto">On 12 Sep 2022, at 15:29, Remi Forax wrote:</p>
</div><div style="white-space:normal"><blockquote style="margin:0px 0px 5px;padding-left:5px;border-left:2px solid rgb(119,119,119);color:rgb(119,119,119)"><blockquote style="margin:0px 0px 5px;padding-left:5px;border-left:2px solid rgb(153,153,153);color:rgb(153,153,153)"><p dir="auto">No new rules; just appeal to type patterns.</p>
</blockquote></blockquote><blockquote style="margin:0px 0px 5px;padding-left:5px;border-left:2px solid rgb(119,119,119);color:rgb(119,119,119)"><p dir="auto">It shows that the semantics you propose for the primitive type pattern is not the right one.</p>
<p dir="auto">Currently, a code like this does not compile
<br>
byte b = ...
<br>
switch(b) {
<br>
case 200 -> ....
<br>
}</p>
<p dir="auto">because 200 is not a short which is great because otherwise at runtime it will never be reached.</p>
<p dir="auto">But if we apply the rules above + your definition of the primitive pattern, the code above will happily compile because it is equivalent to</p>
<p dir="auto">byte b = ...
<br>
switch(b) {
<br>
case short s when s == 200 -> ....
<br>
}</p>
</blockquote></div>
<div style="white-space:normal">
</div></div><br></blockquote></div></div></div></blockquote></div></div>