-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Modify pattern matcher to raise an error instead of generating illegal isInstanceOf[Null] and isInstanceOf[Nothing] #23288
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
base: main
Are you sure you want to change the base?
Conversation
…l isInstanceOf[Null] and isInstanceOf[Nothing] Added a check to the pattern matcher to raise an error when Null or Nothing is used in a type pattern instead of generating isInstanceOf[Null] and isInstanceOf[Nothing] and raising an error later in the erasure phase
IMO there is nothing illegal about the extractor definition. The problem is that patmat should always do a null check first, even if the extractor "handles" |
It is already the case that def unapply(s: String|Null): Boolean = true fails to compile, even without explicit nulls, but with an unhelpful error message (see #23243). All that this PR does is to improve the error message. The spec is silent on whether such an extractor should or should not compile. We need a spec decision on that question first. If the decision is that such an extractor should compile (and should behave the same as How do we make a spec decision? |
As with Supreme Court decisions, case law can result in a change of interpretation, but I think silence means it is not forbidden, although "opinionated Scala" opens the door to forbidding things just for aesthetic reasons. To me, it just looks like a bug. A spec tweak should have a motivating example in the sense of what DX is improved by disallowing the extractor. (Extractor methods are also used outside of pattern matches.) I don't think a spec tweak requires a SIP, especially if it documents existing behavior. "Possession is 9/10ths of the law." |
A method that happens to be named It's the same reason for chick we wouldn't disallow the definition of a method named |
Can we just allow test test on nullable types which is not equivalent to For example, Then, we can raise a warning for matching a nullable type, stating |
… if T is nullable
lazy val tp1Tree = transformTypeTest(e, tp1, flagUnrelated = false) | ||
lazy val tp2Tree = transformTypeTest(e, tp2, flagUnrelated = false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Considering the case String | (Null | Null)
, is it easier to call stripNull
which can remove all Null
from a union type?
Fixes #23243.