bug: compiler crashes with `var s=List.of("a",1)`
Maurizio Cimadamore
maurizio.cimadamore at oracle.com
Wed Mar 21 16:02:31 UTC 2018
Seems like some missing erasure when writing LocalVariableTypeType
attribute.
Thanks for the prompt report.
Maurizio
On 21/03/18 01:54, kishida naoki wrote:
> Hi all!
>
> I'm glad that JDK 10 is released.
> But I've faced a compiler bug with `var`.
> I'm using the build 46.
>
> This code crashes the compiler with `-g` option.
> ```
> public class Main {
> void m() {
> var s = java.util.List.of("a", 1);
> }
> }
> ```
>
> $ javac Main.java -g
> C:\src>javac Main.java -g
> java.lang.AssertionError: Unexpected intersection type:
> java.lang.Object&java.io.Serializable&java.lang.Comparable<? extends
> java.lang.Object&java.io.Serializable&java.lang.Comparable<?>>
> at
> jdk.compiler/com.sun.tools.javac.jvm.ClassWriter.enterInner(ClassWriter.java:1043)
> at
> jdk.compiler/com.sun.tools.javac.jvm.ClassWriter$CWSignatureGenerator.classReference(ClassWriter.java:312)
> at
> jdk.compiler/com.sun.tools.javac.code.Types$SignatureGenerator.assembleClassSig(Types.java:5182)
> at
> jdk.compiler/com.sun.tools.javac.code.Types$SignatureGenerator.assembleSig(Types.java:5114)
> at
> jdk.compiler/com.sun.tools.javac.jvm.ClassWriter$CWSignatureGenerator.assembleSig(ClassWriter.java:291)
> at
> jdk.compiler/com.sun.tools.javac.code.Types$SignatureGenerator.assembleSig(Types.java:5225)
> at
> jdk.compiler/com.sun.tools.javac.code.Types$SignatureGenerator.assembleClassSig(Types.java:5201)
> at
> jdk.compiler/com.sun.tools.javac.code.Types$SignatureGenerator.assembleSig(Types.java:5114)
> at
> jdk.compiler/com.sun.tools.javac.jvm.ClassWriter$CWSignatureGenerator.assembleSig(ClassWriter.java:291)
> at
> jdk.compiler/com.sun.tools.javac.jvm.ClassWriter.typeSig(ClassWriter.java:334)
> at
> jdk.compiler/com.sun.tools.javac.jvm.ClassWriter.writeCode(ClassWriter.java:1271)
> at
> jdk.compiler/com.sun.tools.javac.jvm.ClassWriter.writeMethod(ClassWriter.java:1158)
> at
> jdk.compiler/com.sun.tools.javac.jvm.ClassWriter.writeMethods(ClassWriter.java:1653)
> at
> jdk.compiler/com.sun.tools.javac.jvm.ClassWriter.writeClassFile(ClassWriter.java:1761)
> at
> jdk.compiler/com.sun.tools.javac.jvm.ClassWriter.writeClass(ClassWriter.java:1679)
> at
> jdk.compiler/com.sun.tools.javac.main.JavaCompiler.genCode(JavaCompiler.java:749)
> at
> jdk.compiler/com.sun.tools.javac.main.JavaCompiler.generate(JavaCompiler.java:1627)
> at
> jdk.compiler/com.sun.tools.javac.main.JavaCompiler.generate(JavaCompiler.java:1595)
> at
> jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:965)
> at
> jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:306)
> at
> jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:165)
> at jdk.compiler/com.sun.tools.javac.Main.compile(Main.java:57)
> at jdk.compiler/com.sun.tools.javac.Main.main(Main.java:43)
>
> The cause is about intersection. The variable type that is infered
> becomes as a type with intersection, and will crash the compiler when
> generating a debug info.
> These are no problem.
> var s=List.of("a");
> var s=List.of("a", 1, Optional.empty());
> var s=List.of("a", 1, List.of());
>
> Best regards.
>
> --
> Naoki Kishida
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20180321/51f25ac9/attachment.html>
More information about the compiler-dev
mailing list