<html><body><div id="zimbraEditorContainer" style="font-family: arial, helvetica, sans-serif; font-size: 12pt; color: #000000" class="13"><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>"Ilyas Selimov" <ilyas.selimov@jetbrains.com><br><b>To: </b>"compiler-dev" <compiler-dev@openjdk.java.net><br><b>Sent: </b>Vendredi 3 Septembre 2021 07:27:42<br><b>Subject: </b>Dominance in pattern matching for switch: Spec and Javac inconsistency<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 dir="ltr">Hello!<br><br>The next code compiles correctly, but it seems to contradict the dominance rules:<br><br>void test(Integer i) {<br> switch (i) {<br> case Integer in && in != null:<br> break;<br> case 1:<br> break;<br> case default:<br> break; <br> }<br>}<br><br>> A switch label that has a pattern case label element p dominates another switch label that has a constant case label element c if either of the following is true:<br>> - the type of c is a primitive type and its wrapper class (5.1.7) is a subtype of the erasure of the type of p.<br><br>Maybe the type of p should also be total for the type of selector expression like in the rules for pattern-over-null dominance?</div></blockquote><div><br></div><div>For me, the problem comes from the guard, if you write the same code without the guard, the compiler correctly emits an error<br data-mce-bogus="1"></div><div>void test(Integer i) {<br> switch (i) {<br> case Integer in:<br> break;<br> case 1:<br> break;<br> case default:<br> break; <br> }<br>}</div><div><br data-mce-bogus="1"></div><div>for me, this rule should apply even if p is a guard, the type of p when p is a guard is the type of the type part (the left part) of a guard.</div><div><br data-mce-bogus="1"></div><div>So it's more a bug in the implementation than a spec issue.</div><div>But given that Eclipse has the same issue, the spec should be clarified.<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 dir="ltr"><br><br>Thanks,<br>Ilyas</div></blockquote><div><br></div><div>regards,<br data-mce-bogus="1"></div><div>Rémi<br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div></div></div></body></html>