Skip to content

Commit 3dcb286

Browse files
committed
Merge pull request #584 from smarter/fix/isUnbox
Fix null unboxing of primitives (fixes #582)
2 parents 0edb02b + b033f14 commit 3dcb286

File tree

4 files changed

+24
-12
lines changed

4 files changed

+24
-12
lines changed

src/dotty/tools/dotc/transform/Erasure.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ object Erasure extends TypeTestsCasts{
119119
object Boxing {
120120

121121
def isUnbox(sym: Symbol)(implicit ctx: Context) =
122-
sym.name == nme.unbox && (defn.ScalaBoxedClasses contains sym.owner.linkedClass)
122+
sym.name == nme.unbox && (defn.ScalaValueClasses contains sym.owner.linkedClass)
123123

124124
def isBox(sym: Symbol)(implicit ctx: Context) =
125125
sym.name == nme.box && (defn.ScalaValueClasses contains sym.owner.linkedClass)

tests/pos/nullAsInstanceOf.scala

Lines changed: 0 additions & 11 deletions
This file was deleted.

tests/run/nullAsInstanceOf.check

28 Bytes
Binary file not shown.

tests/run/nullAsInstanceOf.scala

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
object Test {
2+
def main(args: Array[String]): Unit = {
3+
val u = null.asInstanceOf[Unit]
4+
val b = null.asInstanceOf[Byte]
5+
val c = null.asInstanceOf[Char]
6+
val s = null.asInstanceOf[Short]
7+
val i = null.asInstanceOf[Int]
8+
val l = null.asInstanceOf[Long]
9+
val f = null.asInstanceOf[Float]
10+
val d = null.asInstanceOf[Double]
11+
val str = null.asInstanceOf[String]
12+
13+
println(u)
14+
println(b)
15+
println(c)
16+
println(s)
17+
println(i)
18+
println(l)
19+
println(f)
20+
println(d)
21+
println(str)
22+
}
23+
}

0 commit comments

Comments
 (0)