Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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 )
case class IntClassBug[A <: Int]() {
def test(init:A) = {
println("type=" + init.getClass)
}
}
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
scala> new IntClassBug().test(3)
type=class java.lang.Integer
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
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
You can’t perform that action at this time.