This code:
object Test {
def main(args: Array[String]): Unit = {
val d: Double = null.asInstanceOf[Double]
println(d)
}
}
Is transformed both in scalac and dotty into:
def main(args: String[]): Unit = {
val d: Double = scala.Double.unbox(null)
println(scala.Double.box(d))
}
But this is just an illusion: in scalac, the unbox call is actually replaced by BoxesRunTime.unboxToDouble(null). Dotty does not do this replacement and so the call fails with a NullPointerException.
(I still wonder why there even is an implementation in Double.scala since it's both unused and incorrect: https://github.com/scala/scala/blob/2.11.x/src/library/scala/Double.scala#L244)