<html><body><div style="font-family: arial, helvetica, sans-serif; font-size: 12pt; color: #000000"><div>Looks like a bug too me,<br></div><div>the possible combinations are (C, C), (C, D) (D, C) (D,D), they are all covered.</div><div><br data-mce-bogus="1"></div><div>Rémi<br data-mce-bogus="1"></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>"David Alayachew" <davidalayachew@gmail.com><br><b>To: </b>"Mikhail Pyltsin" <pyltsinm@gmail.com><br><b>Cc: </b>"compiler-dev" <compiler-dev@openjdk.org>, "amber-dev" <amber-dev@openjdk.org><br><b>Sent: </b>Friday, July 7, 2023 10:43:26 PM<br><b>Subject: </b>Re: Exhaustiveness for record pattern with switch (JEP 440+441)<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"><div class="gmail_default" style="font-family:monospace">I've CC'd the Amber Dev Team.<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Jul 7, 2023 at 1:52 PM Mikhail Pyltsin <<a href="mailto:pyltsinm@gmail.com" target="_blank">pyltsinm@gmail.com</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 dir="ltr"><div>Hi!<br>I investigated the algorithm, which Javac 21 (Build 30 (2023/7/6))</div><div>) uses to check exhaustiveness for record patterns (JEP 440+441), and found the strange behavior:<br>- let's take compilable code<br>```<br>class Test22 {<br><br>  record Pair(I i1, I i2) {}<br><br>  sealed interface I {}<br><br>  record C() implements I {}<br><br>  record D() implements I {}<br><br>  void exhaustinvenessWithInterface(Pair pairI) {<br>    switch (pairI) {<br>      case Pair(C fst, D snd) -> {<br>      }<br>      case Pair(C fst, C snd) -> {<br>      }<br>      case Pair(I fst, C snd) -> {<br>      }<br>      case Pair(D fst, D snd) -> {<br>      }<br>    }<br>  }<br>}<br>```<br>- If we swap types of components, it starts to produce the error "java: the switch statement does not cover all possible input values":<br>```<br>  void exhaustinvenessWithInterface(Pair pairI) {<br>    switch (pairI) {<br>      case Pair(D fst, C snd) -> {<br>      }<br>      case Pair(C fst, C snd) -> {<br>      }<br>      case Pair(C fst, I snd) -> {<br>      }<br>      case Pair(D fst, D snd) -> {<br>      }<br>    }<br>  }<br>```<br>It happens because Javac tries to find the first distinguished type from the beginning, but I couldn't find any mention of it in JEP.<br>Is this the expected behavior?<br><br></div></div>
</blockquote></div><br></blockquote></div></div></body></html>