Skip to content

null asInstance of Nothing not always throwing #3340

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
nicolasstucki opened this issue Oct 17, 2017 · 1 comment
Closed

null asInstance of Nothing not always throwing #3340

nicolasstucki opened this issue Oct 17, 2017 · 1 comment

Comments

@nicolasstucki
Copy link
Contributor

nicolasstucki commented Oct 17, 2017

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.

@nicolasstucki
Copy link
Contributor Author

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

with -optimise throws, that was how I discovered the issue.

nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Feb 7, 2019
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Feb 8, 2019
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Feb 8, 2019
nicolasstucki added a commit that referenced this issue Feb 8, 2019
Fix #3340: Always throw when casting to scala.Nothing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant