<html><body><div style="font-family: arial, helvetica, sans-serif; font-size: 12pt; color: #000000"><div><br></div><div><br></div><hr id="zwchr" data-marker="__DIVIDER__"><div data-marker="__HEADERS__"><blockquote style="border-left:2px solid #1010FF;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt;"><b>From: </b>"John Rose" <john.r.rose@oracle.com><br><b>To: </b>"Remi Forax" <forax@univ-mlv.fr><br><b>Cc: </b>"Brian Goetz" <brian.goetz@oracle.com>, "amber-spec-experts" <amber-spec-experts@openjdk.java.net><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 data-marker="__QUOTED_TEXT__"><blockquote style="border-left:2px solid #1010FF;margin-left:5px;padding-left:5px;color:#000;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 class="markdown" 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 data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div><blockquote style="border-left:2px solid #1010FF;margin-left:5px;padding-left:5px;color:#000;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 class="markdown" 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: 0; padding: 0 0.4em; border-radius: 3px; background-color: #F7F7F7;">"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: 0; padding: 0 0.4em; border-radius: 3px; background-color: #F7F7F7;">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: 0; padding: 0 0.4em; border-radius: 3px; background-color: #F7F7F7;">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 data-mce-bogus="1"></div><div>so if you have both pattern in a switch, users will spot the inconsistency.<br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div><div>something like<br data-mce-bogus="1"></div><div> byte b = ...<br data-mce-bogus="1"></div><div> switch(b) {<br data-mce-bogus="1"></div><div> case 200 -> ... // does not compile, incompatible types between byte and int<br data-mce-bogus="1"></div><div> case int i -> ... // ok, compiles<br data-mce-bogus="1"></div><div> }<br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></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 data-mce-bogus="1"></div><div><br data-mce-bogus="1"></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 data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div><div>Rémi<br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div><blockquote style="border-left:2px solid #1010FF;margin-left:5px;padding-left:5px;color:#000;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 class="markdown" style="white-space: normal;">
<p dir="auto">On 12 Sep 2022, at 15:29, Remi Forax wrote:</p>
</div><div class="plaintext" style="white-space: normal;"><blockquote style="margin: 0 0 5px; padding-left: 5px; border-left: 2px solid #777777; color: #777777;"><blockquote style="margin: 0 0 5px; padding-left: 5px; border-left: 2px solid #777777; border-left-color: #999999; color: #999999;"><p dir="auto">No new rules; just appeal to type patterns.</p>
</blockquote></blockquote><blockquote style="margin: 0 0 5px; padding-left: 5px; border-left: 2px solid #777777; color: #777777;"><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 class="markdown" style="white-space: normal;">
</div></div><br></blockquote></div></div></body></html>