-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Null checks with pattern matching are not reflected to the return type with -Yexplicit-nulls
#11967
Comments
Currently, the flow typing of explicit nulls only detects the NotNull cases in pattern matching (see For example: val s: String | Null = ???
s match {
case _: String => println(s.length)
case _ => println(0)
} I think it would be better to detect the null case as well. |
Sorry, I made a mistake. The null case is indeed detected by flow typing. If you write it in this way, then it can be compiled. def f(s: String | Null): String = s match {
case null => "other"
case _ => s
} |
It is a new variable yes, but it's defined after the |
The variables binded by the patterns are not handled by flow typing now. I agree we should consider them as well. |
Compiler version
Scala 3.0.0-RC2 with
-Yexplicit-nulls
Minimized code
Output
Expectation
My expectation is that what happens with
def f(s: String | Null): String = if(s == null) "other" else s
should apply to pattern matching too.I couldn't find any open issue treating this, so I opened one.
Thank you.
The text was updated successfully, but these errors were encountered: