<!DOCTYPE html><html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body><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>
<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>
<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></body>
</html>