Last active
August 29, 2015 14:11
-
-
Save hyamamoto/ad177fe9233536bfc2ec to your computer and use it in GitHub Desktop.
I came across a compiler bug that involves a generics type with `scala.Int` . This can be one of the examples to show how they're handling primitive types internally. (Fixed in scala 2.10.1-RC1 by https://github.com/scala/scala/pull/1904 )
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
case class IntClassBug[A <: Int]() { | |
def test(init:A) = { | |
println("type=" + init.getClass) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void test(A); | |
Code: | |
0: getstatic #21; // Field scala/Predef$.MODULE$:Lscala/Predef$; | |
3: new #23; // class scala/collection/mutable/StringBuilder | |
6: dup | |
7: invokespecial #27; // Method scala/collection/mutable/StringBuilder."<init>":()V | |
10: ldc #29; // String type= | |
12: invokevirtual #33; // Method scala/collection/mutable/StringBuilder.append:(Ljava/lang/Object;)Lscala/collection/mutable/StringBuilder; | |
15: iload_1 | |
16: invokestatic #39; // Method scala/runtime/BoxesRunTime.boxToInteger:(I)Ljava/lang/Integer; | |
19: invokevirtual #43; // Method java/lang/Object.getClass:()Ljava/lang/Class; | |
22: invokevirtual #33; // Method scala/collection/mutable/StringBuilder.append:(Ljava/lang/Object;)Lscala/collection/mutable/StringBuilder; | |
25: invokevirtual #47; // Method scala/collection/mutable/StringBuilder.toString:()Ljava/lang/String; | |
28: invokevirtual #51; // Method scala/Predef$.println:(Ljava/lang/Object;)V | |
31: return |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scala> new IntClassBug().test(3) | |
type=class java.lang.Integer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void test(A); | |
Code: | |
0: getstatic #25; // Field scala/Predef$.MODULE$:Lscala/Predef$; | |
3: new #27; // class scala/collection/mutable/StringBuilder | |
6: dup | |
7: invokespecial #31; // Method scala/collection/mutable/StringBuilder."<init>":()V | |
10: ldc #33; // String type= | |
12: invokevirtual #37; // Method scala/collection/mutable/StringBuilder.append:(Ljava/lang/Object;)Lscala/collection/mutable/StringBuilder; | |
15: iload_1 | |
16: invokevirtual #43; // Method scala/Int.getClass:()Ljava/lang/Class; | |
19: invokevirtual #37; // Method scala/collection/mutable/StringBuilder.append:(Ljava/lang/Object;)Lscala/collection/mutable/StringBuilder; | |
22: invokevirtual #47; // Method scala/collection/mutable/StringBuilder.toString:()Ljava/lang/String; | |
25: invokevirtual #51; // Method scala/Predef$.println:(Ljava/lang/Object;)V | |
28: return |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scala> new IntClassBug().test(3) | |
java.lang.VerifyError: (class: IntClassBug, method: test signature: (I)V) Expecting to find object/array on stack | |
at .<init>(<console>:8) | |
at .<clinit>(<console>) | |
at .<init>(<console>:11) | |
at .<clinit>(<console>) | |
at $print(<console>) | |
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) | |
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) | |
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) | |
at java.lang.reflect.Method.invoke(Method.java:606) | |
at scala.tools.nsc.interpreter.IMain$ReadEvalPrint.call(IMain.scala:704) | |
at scala.tools.nsc.interpreter.IMain$Request$$anonfun$14.apply(IMain.scala:920) | |
at scala.tools.nsc.interpreter.Line$$anonfun$1.apply$mcV$sp(Line.scala:43) | |
at scala.tools.nsc.io.package$$anon$2.run(package.scala:25) | |
at java.lang.Thread.run(Thread.java:745) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment