<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div>Hi</div><div><br class=""></div><div>If I understand correctly, a guarded switch label effectively can't dominate any other labels, since the spec doesn't go into trying to statically analyse whether or not the guard could ever be false.</div><div>I guess the spec could mention that (but it would be a comment, since it follows from the other rules).</div><div><br class=""></div><div>-Jesper</div><div><br class=""></div><div><br class=""><blockquote type="cite" class=""><div class="">On 3 Sep 2021, at 09.29, Remi Forax <<a href="mailto:forax@univ-mlv.fr" class="">forax@univ-mlv.fr</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta charset="UTF-8" class=""><div style="caret-color: rgb(0, 0, 0); font-family: arial, helvetica, sans-serif; font-size: 16px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><br class="Apple-interchange-newline"><br class=""></div><hr id="zwchr" data-marker="__DIVIDER__" style="caret-color: rgb(0, 0, 0); font-family: arial, helvetica, sans-serif; font-size: 16px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><div data-marker="__HEADERS__" style="caret-color: rgb(0, 0, 0); font-family: arial, helvetica, sans-serif; font-size: 16px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><blockquote style="border-left-width: 2px; border-left-style: solid; border-left-color: rgb(16, 16, 255); margin-left: 5px; padding-left: 5px; font-weight: normal; font-style: normal; text-decoration: none; font-family: Helvetica, Arial, sans-serif; font-size: 12pt;" class=""><b class="">From:<span class="Apple-converted-space"> </span></b>"Ilyas Selimov" <<a href="mailto:ilyas.selimov@jetbrains.com" class="">ilyas.selimov@jetbrains.com</a>><br class=""><b class="">To:<span class="Apple-converted-space"> </span></b>"compiler-dev" <<a href="mailto:compiler-dev@openjdk.java.net" class="">compiler-dev@openjdk.java.net</a>><br class=""><b class="">Sent:<span class="Apple-converted-space"> </span></b>Vendredi 3 Septembre 2021 07:27:42<br class=""><b class="">Subject:<span class="Apple-converted-space"> </span></b>Dominance in pattern matching for switch: Spec and Javac inconsistency<br class=""></blockquote></div><div data-marker="__QUOTED_TEXT__" style="caret-color: rgb(0, 0, 0); font-family: arial, helvetica, sans-serif; font-size: 16px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><blockquote style="border-left-width: 2px; border-left-style: solid; border-left-color: rgb(16, 16, 255); margin-left: 5px; padding-left: 5px; font-weight: normal; font-style: normal; text-decoration: none; font-family: Helvetica, Arial, sans-serif; font-size: 12pt;" class=""><div dir="ltr" class="">Hello!<br class=""><br class="">The next code compiles correctly, but it seems to contradict the dominance rules:<br class=""><br class="">void test(Integer i) {<br class=""> switch (i) {<br class=""> case Integer in && in != null:<br class=""> break;<br class=""> case 1:<br class=""> break;<br class=""> case default:<br class=""> break; <br class=""> }<br class="">}<br class=""><br class="">> 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 class="">> - 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 class=""><br class="">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 class=""><br class=""></div><div class="">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" class=""></div><div class="">void test(Integer i) {<br class=""> switch (i) {<br class=""> case Integer in:<br class=""> break;<br class=""> case 1:<br class=""> break;<br class=""> case default:<br class=""> break; <br class=""> }<br class="">}</div><div class=""><br data-mce-bogus="1" class=""></div><div class="">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 class=""><br data-mce-bogus="1" class=""></div><div class="">So it's more a bug in the implementation than a spec issue.</div><div class="">But given that Eclipse has the same issue, the spec should be clarified.<br data-mce-bogus="1" class=""></div><div class=""><br data-mce-bogus="1" class=""></div><blockquote style="border-left-width: 2px; border-left-style: solid; border-left-color: rgb(16, 16, 255); margin-left: 5px; padding-left: 5px; font-weight: normal; font-style: normal; text-decoration: none; font-family: Helvetica, Arial, sans-serif; font-size: 12pt;" class=""><div dir="ltr" class=""><br class=""><br class="">Thanks,<br class="">Ilyas</div></blockquote><div class=""><br class=""></div><div class="">regards,<br data-mce-bogus="1" class=""></div><div class="">Rémi</div></div></div></blockquote></div><br class=""></body></html>