From 90039fcf18c28a0f89271e6b1fbb6dfd36e1d4ba Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Sat, 4 Feb 2012 21:47:05 -0800 Subject: Fixing AnyVal verify error and reflection. Have to give AnyVal a constructor and simultaneously pacify both the typer (which knows Any has no constructor) and the jvm (which mandates a constructor must call its superconstructor.) It's the usual angle of adding a not-quite-right tree during parsing and then finishing it later (in this case, in AddInterfaces.) --- src/compiler/scala/tools/nsc/transform/AddInterfaces.scala | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/compiler/scala/tools/nsc/transform/AddInterfaces.scala b/src/compiler/scala/tools/nsc/transform/AddInterfaces.scala index 8fe82258e2..971a0c9aab 100644 --- a/src/compiler/scala/tools/nsc/transform/AddInterfaces.scala +++ b/src/compiler/scala/tools/nsc/transform/AddInterfaces.scala @@ -308,8 +308,13 @@ abstract class AddInterfaces extends InfoTransform { case (presuper, supercall :: rest) => stats span (t => t.hasSymbolWhich(_ hasFlag PRESUPER)) treeCopy.Block(tree, presuper ::: (supercall :: mixinConstructorCalls ::: rest), expr) - case (Nil, Nil) => // AnyVal constructor - Literal(Constant()) + case (Nil, Nil) => + // AnyVal constructor - have to provide a real body so the + // jvm doesn't throw a VerifyError. But we can't add the + // body until now, because the typer knows that Any has no + // constructor and won't accept a call to super.init. + val superCall = Apply(Select(Super(This(tpnme.EMPTY), tpnme.EMPTY), nme.CONSTRUCTOR), Nil) + Block(List(superCall), Literal(Constant())) } } } -- cgit v1.2.3