-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Disallow type Null in a type pattern or isInstanceOf test #4004
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
Comments
I would say yes, same with Singleton. |
Maybe we should translate |
But what's the usecase? :) |
This can only be done if the callee is a subtype of |
The main point is that we should at least not do it for singletons. The one with |
So somebody could just forbid isInstanceOf[Null] and see if something breaks. Volunteers? @liufengyun maybe in your PR when you have time? Pattern matching with singleton types (which is equivalent to def f[T, U](t: Foo[T], u: Foo[U]) =
t match {
case _: u.type => // Here T and U are equal
} An actual use case is in ECOOP'07 Burak Emir's paper on case classes, and that code still works today in Scala (though IIRC not yet in Dotty). |
I also think we should try to disallow |
One then also needs to check that e match
case x: Null => ... is rejected. |
Scala 2.13.6 also rejects |
Fixes #4004 `isInstanceOf[Nothing]` checks are always prohibited `isInstanceOf[Null]` checks are probihibited unless they can be proven at compiletime, then thay are simplified to `true`
Fixes #4004 `isInstanceOf[Nothing]` checks are always prohibited `isInstanceOf[Null]` checks are probihibited unless they can be proven at compiletime, then thay are simplified to `true`
Fixes scala#4004 `isInstanceOf[Nothing]` checks are always prohibited `isInstanceOf[Null]` checks are probihibited unless they can be proven at compiletime, then thay are simplified to `true`
Should we disallow type
Null
in a type pattern orisInstanceOf
test like scalac does to avoid surprising behaviors?Dotty:
Scalac:
The text was updated successfully, but these errors were encountered: