Skip to content
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

Inconsistency between spec and behavior of null.asInstanceOf[Int] #5236

Closed
scabug opened this issue Nov 27, 2011 · 3 comments
Closed

Inconsistency between spec and behavior of null.asInstanceOf[Int] #5236

scabug opened this issue Nov 27, 2011 · 3 comments

Comments

@scabug
Copy link

scabug commented Nov 27, 2011

In the specification, section 6.3 (page 75 of the May 24, 2011 draft) it says:

The null value is of type scala.Null, and is thus compatible with every reference type. It denotes a reference value which refers to a special "null" object. This object implements methods in class scala.AnyRef as follows:

  • ...
  • asInstanceOf[T] returns the "null" object itself if T conforms to scala.AnyRef, and throws a NullPointerException otherwise.

Yet null.asInstanceOf[Int\] returns 0 instead of throwing an exception. Either the compiler is wrong or the spec needs to be updated.

This was found by 爱国者 on http://stackoverflow.com/questions/8285916/why-doesnt-null-asinstanceofint-throw-a-nullpointerexception

@scabug
Copy link
Author

scabug commented Nov 27, 2011

Imported From: https://issues.scala-lang.org/browse/SI-5236?orig=1
Reporter: huynhjl
Affected Versions: 2.7.7, 2.9.1, 2.10.0
See #4437

@scabug
Copy link
Author

scabug commented Nov 27, 2011

@dcsobral said:
Duplicate of #5234, but much clearly described.

@scabug
Copy link
Author

scabug commented Nov 27, 2011

@paulp said:
And both are duplicates of #4437.

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

2 participants