Record Pattern with swich has something wrong

Blaise B. blaisebass at gmail.com
Fri Mar 24 14:58:51 UTC 2023


Hello!

I could still reproduce the bug on JDK 21 EA
(openjdk-21-ea+15_windows-x64_bin) with a slightly different code:

public class Main {
       record Foo(Object first, Object second) {}

       public static void main(String[] args) {
               Foo myfoo = new Foo(42, "millis");

               switch (myfoo) {
                   case Foo(Integer d, String s)  ->
System.out.println("got integer and string: " + d + ", " + s);
                   case Foo(Object fs, Object sc) ->
System.out.println("values: " + fs + ", " + sc);
              }
       }
}


>javac --release 21 --enable-preview Main.java
Note: Main.java uses preview features of Java SE 21.
Note: Recompile with -Xlint:preview for details.


>java --enable-preview Main
Error: Unable to initialize main class Main
Caused by: java.lang.VerifyError: Bad local variable type
Exception Details:
  Location:
    Main.main([Ljava/lang/String;)V @192: aload
  Reason:
    Type top (current frame, locals[8]) is not assignable to reference type
  Current Frame:
    bci: @192
    flags: { }
    locals: { '[Ljava/lang/String;', 'Main$Foo', 'Main$Foo', integer,
'Main$Foo', top, top, 'java/lang/Object', top, 'java/lang/Object', integer }
    stack: { 'java/io/PrintStream', 'java/lang/String' }
  Bytecode:
    0000000: bb00 0759 05b8 0009 120f b700 114c 2b59
    0000010: b800 1457 4d03 3e2c 1dba 001a 0000 ab00
    0000020: 0000 0012 0000 0001 0000 0000 0000 001c
    0000030: bb00 1e59 0101 b700 20bf 2c3a 0419 04b6
    0000040: 0023 3a09 0336 0a19 0915 0aba 0027 0000
    0000050: aa00 0000 0000 0080 ffff ffff 0000 0001
    0000060: 0000 0054 0000 001c 0000 0054 1909 c000
    0000070: 0a3a 0519 04b6 0028 3a0b 190b c100 2b99
    0000080: 000d 190b c000 2b3a 06a7 0009 0436 0aa7
    0000090: ffb8 b200 2d19 0519 06ba 0033 0000 b600
    00000a0: 37a7 0034 1909 3a07 1907 c600 0e19 04b6
    00000b0: 0028 3a0b 190b 3a08 b200 2d19 07b8 003d
    00000c0: 1908 b800 3dba 0040 0000 b600 37a7 0008
    00000d0: 043e a7ff 45a7 0011 4dbb 001e 592c b600
    00000e0: 452c b700 20bf b1
  Exception Handler Table:
    bci [63, 66] => handler: 216
    bci [117, 120] => handler: 216
    bci [175, 178] => handler: 216
  Stackmap Table:
    append_frame(@23,Object[#7],Object[#7],Integer)
    same_frame(@48)
    same_frame(@58)

full_frame(@71,{Object[#80],Object[#7],Object[#7],Integer,Object[#7],Top,Top,Top,Top,Object[#2],Integer},{})
    same_frame(@108)

full_frame(@140,{Object[#80],Object[#7],Object[#7],Integer,Object[#7],Object[#10],Top,Top,Top,Object[#2],Integer},{})

full_frame(@146,{Object[#80],Object[#7],Object[#7],Integer,Object[#7],Object[#10],Object[#43],Top,Top,Object[#2],Integer},{})

full_frame(@164,{Object[#80],Object[#7],Object[#7],Integer,Object[#7],Top,Top,Top,Top,Object[#2],Integer},{})

full_frame(@184,{Object[#80],Object[#7],Object[#7],Integer,Object[#7],Top,Top,Object[#2],Top,Object[#2],Integer},{})

full_frame(@208,{Object[#80],Object[#7],Object[#7],Integer,Object[#7],Top,Top,Top,Top,Object[#2],Integer},{})
    full_frame(@213,{Object[#80],Object[#7]},{})
    full_frame(@216,{Object[#80]},{Object[#67]})
    append_frame(@230,Object[#7])
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-dev/attachments/20230324/be12c844/attachment-0001.htm>


More information about the amber-dev mailing list