<div dir="ltr">Hello team,<br>I would like to report a behavior I stumbled upon when a record pattern in switch is unconditional.<br><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">public class Main {<br>      record SomeRecord(Number num) {}<br>      public static void main(String[] args) {<br>                   //var rec = new SomeRecord(null);<br>           var rec = new SomeRecord(1.0f);<br>            switch (rec) {<br>                   case SomeRecord(Double d) -> System.out.println("got a double: " + d);<br>                   case SomeRecord(Number n) -> System.out.println("value is " + n);<br>            }<br>       }<br>  }</blockquote><div><br></div><div>Here, I expect variable "n" to be of type Number, but instead it displays "value is SomeRecord[num=1.0]". When I comment out the first case label, it works as expected.<br>The issue is not present on JDK 19. I've observed it only on EA builds of jdk-20 and jdk-21.<br></div><div><br></div><div>I also tried a record with two components:<br><br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">   public class Main {<br>          record Foo(Number num, String s) {}<br>          public static void main(String[] args) {<br>                Foo myfoo = new Foo(2, "me");<br>                 switch (myfoo) {<br>                       case Foo(Double d, String s) -> System.out.println("component values: " + d + ", " + s);<br>                       case Foo(Number n, String s) -> System.out.println("component values: " + n + ", " + s);<br>                 }<br>            }<br>     }</blockquote>        <br>This time, the code compiles but fails to run with error message:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">          Error: Unable to initialize main class Main<br>          Caused by: java.lang.VerifyError: Bad local variable type</blockquote><br>Again it works fine on jdk-19.<br><br>Hope this helps.<br>Regards,<br></div><div><br></div><div><br></div></div>