summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJosh Suereth <Joshua.Suereth@gmail.com>2012-07-30 17:36:50 -0700
committerJosh Suereth <Joshua.Suereth@gmail.com>2012-07-30 17:36:50 -0700
commitf4693871f4aad1fdbdbb743feaed8a848a9e2dca (patch)
tree3f813ed8c97beef93ec651d74fb945c598f1ec1a /src
parent123d14cf6a05f033762db6b57f2c56f20569d84c (diff)
parent5589eeeb9a5e09352544efc629013caf2d18a842 (diff)
downloadscala-f4693871f4aad1fdbdbb743feaed8a848a9e2dca.tar.gz
scala-f4693871f4aad1fdbdbb743feaed8a848a9e2dca.tar.bz2
scala-f4693871f4aad1fdbdbb743feaed8a848a9e2dca.zip
Merge pull request #1020 from odersky/ticket/5866
SI-5866 Support casting null to value classes
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scala/tools/nsc/transform/Erasure.scala12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/Erasure.scala b/src/compiler/scala/tools/nsc/transform/Erasure.scala
index 5115c49c87..24a74722b0 100644
--- a/src/compiler/scala/tools/nsc/transform/Erasure.scala
+++ b/src/compiler/scala/tools/nsc/transform/Erasure.scala
@@ -563,8 +563,16 @@ abstract class Erasure extends AddInterfaces
case _ =>
val clazz = tref.sym
log("not boxed: "+tree)
- val tree0 = adaptToType(tree, clazz.tpe)
- cast(Apply(Select(tree0, clazz.derivedValueClassUnbox), List()), pt)
+ lazy val underlying = underlyingOfValueClass(clazz)
+ val tree0 =
+ if (tree.tpe.typeSymbol == NullClass &&
+ isPrimitiveValueClass(underlying.typeSymbol)) {
+ // convert `null` directly to underlying type, as going
+ // via the unboxed type would yield a NPE (see SI-5866)
+ unbox1(tree, underlying)
+ } else
+ Apply(Select(adaptToType(tree, clazz.tpe), clazz.derivedValueClassUnbox), List())
+ cast(tree0, pt)
}
case _ =>
pt.typeSymbol match {