<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>"Tesla Ice Zhang" <ice1000kotlin@foxmail.com><br><b>To: </b>"amber-dev" <amber-dev@openjdk.org><br><b>Sent: </b>Wednesday, November 2, 2022 7:59:52 PM<br><b>Subject: </b>Question regarding exhaustiveness check of record patterns<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;">Hi,<br><div>I am confused by a compile error generated by the following code:</div><br><div><div>sealed interface I<T> {}</div><div>record A<T>(T t) implements I<T> {}</div><div>public static void main(I<String> args) {</div><div> switch (args) {</div><div> case A<String>(var x) -> System.out.println(x);</div><div> }</div><div>}</div></div><br><div>Compiling the code with the following JDK:</div><br><div><div>openjdk 19 2022-09-20</div><div>OpenJDK Runtime Environment (build 19+37)</div><div>OpenJDK 64-Bit Server VM (build 19+37, mixed mode, sharing)</div></div><br><div>I get:</div><br><div><div>.\JavaBug.java:5: error: the switch statement does not cover all possible input values</div><div> switch (args) {</div><div> ^</div><div>Note: .\JavaBug.java uses preview features of Java SE 19.</div><div>Note: Recompile with -Xlint:preview for details.</div><div>1 error</div></div><br><div>What cases could be not covered? It looks like a bug to me.</div></blockquote><div><br></div><div>It is a bug, i'm able to reproduce it.<br></div><div><br data-mce-bogus="1"></div><div>TeslaSwitchTest.java:6: error: the switch statement does not cover all possible input values<br> switch (args) {<br> ^<br>Note: TeslaSwitchTest.java uses preview features of Java SE 20.<br>Note: Recompile with -Xlint:preview for details.<br>1 error<br></div><div><br data-mce-bogus="1"></div><div>As a workaround, using a type parameter works<br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div><div> static <T> void main(I<T> args) {<br> switch (args) {<br> case A<T>(var x) -> System.out.println(x);<br> }<br> }<br><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;"><br><div>Also, I believe that showing the particular uncovered cases in the error messages would make very good developer experiences.</div></blockquote><div><br></div><div>yes !<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;"><br><div>Best regards,</div><div>Tesla</div></blockquote><div><br></div><div>Rémi<br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div></div></div></body></html>