You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
java.lang.NullPointerException
at .<init>(<console>:10)
at .<clinit>(<console>)
at .<init>(<console>:7)
at .<clinit>(<console>)
at $print(<console>)
This behavior is problematic because code in the standard library relies on the fact that casting null to a type returns the "default" value of this type (as specified in §4.2):
Outdatedspec: asInstanceOf[T] returns the nullobjectitselfifT conforms to scala.AnyRef, and throws a NullPointerException otherwise.
Proposedupdate: asInstanceOf[T] returns the default value of that type, asspecified in 4.2.
(4.2 probably needs some update in the line of "the default value of a value class is an instance of the value class with the default value of its enclosing member".
Casting from null should be made to behave like existing AnyVal and AnyRef classes, so that NPE won't happen in surprising special cases.
The text was updated successfully, but these errors were encountered:
This behavior is problematic because code in the standard library relies on the fact that casting null to a type returns the "default" value of this type (as specified in §4.2):
See also the spec clarifications decided in the second part of #4437 (which I tried to reflect in the spec https://github.com/soc/scala-dist/commit/39337a8e620ea59830fc89a323b17b6ce9917975#L2L4039 ):
(4.2 probably needs some update in the line of "the default value of a value class is an instance of the value class with the default value of its enclosing member".
Casting from null should be made to behave like existing AnyVal and AnyRef classes, so that NPE won't happen in surprising special cases.
The text was updated successfully, but these errors were encountered: