Skip to content

null asInstance of Nothing not always throwing #3340

Closed
@nicolasstucki

Description

@nicolasstucki

In the following code the cast to Nothing does not throw the expected NullPointerException

def f: Unit = {
  val a: Nothing = null.asInstanceOf[Nothing] // No exception
}

but it does in

def f: Unit = {
  val a: Nothing = null.asInstanceOf[Nothing]
  println(a) // throws here
}
def f: Unit = {
  val a: Int = null.asInstanceOf[Nothing] // throws here
}
def f: Unit = {
  null.asInstanceOf[Nothing] // throws here
}

This issue was metioned prevoiusly in #1002.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions