summaryrefslogtreecommitdiff
path: root/src/compiler
diff options
context:
space:
mode:
authorMiguel Garcia <miguelalfredo.garcia@epfl.ch>2013-04-03 13:05:12 +0200
committerMiguel Garcia <miguelalfredo.garcia@epfl.ch>2013-04-24 22:37:26 +0200
commit8dc0c3dd4cff261a61f146554d43e75f24c02a4d (patch)
tree1bf51deb4b2e61883ea1ba4f76e734ea96c3b335 /src/compiler
parent10845adebe741fc2bb5bce70df0a8da7788aa722 (diff)
downloadscala-8dc0c3dd4cff261a61f146554d43e75f24c02a4d.tar.gz
scala-8dc0c3dd4cff261a61f146554d43e75f24c02a4d.tar.bz2
scala-8dc0c3dd4cff261a61f146554d43e75f24c02a4d.zip
for null outer pointer, NPE via throw null
As per the JVM spec, the athrow instruction throws a NullPointerException upon finding null on stack top. This commit takes advantage of that feature, to emit more compact code. The constructor of an inner class that receives an outer value first checks that value for nullness, depending on which NPE may be thrown. The code now emitted to achieve the above looks like: 0: aload_1 1: ifnonnull 6 4: aconst_null 5: athrow 6: ...
Diffstat (limited to 'src/compiler')
-rw-r--r--src/compiler/scala/tools/nsc/transform/Constructors.scala3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/Constructors.scala b/src/compiler/scala/tools/nsc/transform/Constructors.scala
index 06367009b6..fe8bad3e3a 100644
--- a/src/compiler/scala/tools/nsc/transform/Constructors.scala
+++ b/src/compiler/scala/tools/nsc/transform/Constructors.scala
@@ -164,7 +164,8 @@ abstract class Constructors extends Transform with ast.TreeDSL {
if (from.name != nme.OUTER ||
from.tpe.typeSymbol.isPrimitiveValueClass) result
else localTyper.typedPos(to.pos) {
- IF (from OBJ_EQ NULL) THEN Throw(NewFromConstructor(NPEConstructor)) ELSE result
+ // `throw null` has the same effect as `throw new NullPointerException`, see JVM spec on instruction `athrow`
+ IF (from OBJ_EQ NULL) THEN Throw(gen.mkZero(ThrowableClass.tpe)) ELSE result
}
}