From b033f14dc28122d2b1795f1411c7b290c5d7bc67 Mon Sep 17 00:00:00 2001 From: Guillaume Martres Date: Mon, 18 May 2015 00:13:06 +0200 Subject: [PATCH] Fix null unboxing of primitives (fixes #582) Erasure#isUnbox was incorrect: the unbox methods are defined on the value classes, not the boxed classes. --- src/dotty/tools/dotc/transform/Erasure.scala | 2 +- tests/pos/nullAsInstanceOf.scala | 11 --------- tests/run/nullAsInstanceOf.check | Bin 0 -> 28 bytes tests/run/nullAsInstanceOf.scala | 23 +++++++++++++++++++ 4 files changed, 24 insertions(+), 12 deletions(-) delete mode 100644 tests/pos/nullAsInstanceOf.scala create mode 100644 tests/run/nullAsInstanceOf.check create mode 100644 tests/run/nullAsInstanceOf.scala diff --git a/src/dotty/tools/dotc/transform/Erasure.scala b/src/dotty/tools/dotc/transform/Erasure.scala index 996c480ce778..36d75b149c54 100644 --- a/src/dotty/tools/dotc/transform/Erasure.scala +++ b/src/dotty/tools/dotc/transform/Erasure.scala @@ -119,7 +119,7 @@ object Erasure extends TypeTestsCasts{ object Boxing { def isUnbox(sym: Symbol)(implicit ctx: Context) = - sym.name == nme.unbox && (defn.ScalaBoxedClasses contains sym.owner.linkedClass) + sym.name == nme.unbox && (defn.ScalaValueClasses contains sym.owner.linkedClass) def isBox(sym: Symbol)(implicit ctx: Context) = sym.name == nme.box && (defn.ScalaValueClasses contains sym.owner.linkedClass) diff --git a/tests/pos/nullAsInstanceOf.scala b/tests/pos/nullAsInstanceOf.scala deleted file mode 100644 index 2662df72eb85..000000000000 --- a/tests/pos/nullAsInstanceOf.scala +++ /dev/null @@ -1,11 +0,0 @@ -object Test { - val b = null.asInstanceOf[Byte] - val c = null.asInstanceOf[Char] - val s = null.asInstanceOf[Short] - val i = null.asInstanceOf[Int] - val l = null.asInstanceOf[Long] - val f = null.asInstanceOf[Float] - val d = null.asInstanceOf[Double] - - val str = null.asInstanceOf[String] -} diff --git a/tests/run/nullAsInstanceOf.check b/tests/run/nullAsInstanceOf.check new file mode 100644 index 0000000000000000000000000000000000000000..3cc997cd79e8d70399747196d505ea2942b01e3c GIT binary patch literal 28 Zcmc~R&B@_1;9>w`Fw_H*K%55>1^`kk1+4%8 literal 0 HcmV?d00001 diff --git a/tests/run/nullAsInstanceOf.scala b/tests/run/nullAsInstanceOf.scala new file mode 100644 index 000000000000..7924ff833580 --- /dev/null +++ b/tests/run/nullAsInstanceOf.scala @@ -0,0 +1,23 @@ +object Test { + def main(args: Array[String]): Unit = { + val u = null.asInstanceOf[Unit] + val b = null.asInstanceOf[Byte] + val c = null.asInstanceOf[Char] + val s = null.asInstanceOf[Short] + val i = null.asInstanceOf[Int] + val l = null.asInstanceOf[Long] + val f = null.asInstanceOf[Float] + val d = null.asInstanceOf[Double] + val str = null.asInstanceOf[String] + + println(u) + println(b) + println(c) + println(s) + println(i) + println(l) + println(f) + println(d) + println(str) + } +}