Skip to content

null.asInstanceOf[T] where T is a value type results in NullPointerException #8097

Open
@scabug

Description

While the direct route of

case class Foo(d: Double) extends AnyVal
null.asInstanceOf[Foo]

was fixed in #5866, the issue remains when Generics get involved:

scala> case class Foo(d: Double) extends AnyVal
defined class Foo

scala> def newInst[T] = null.asInstanceOf[T]
newInst: [T]=> T

scala> newInst[Foo]
java.lang.NullPointerException
  ... 32 elided

Metadata

Assignees

No one assigned

    Labels

    backendfixed in Scala 3This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/)valueclass

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions