-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Relax comparison between Null and reference types in explicit nulls #23308
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
Conversation
04432cb
to
c909ba2
Compare
Before this PR, all three errors in
After this PR, the two errors on lines 6 and 12 understandably go away. The error on line 5 prevents the compiler from getting past typer, so match reachability checking never happens. The test was not intended for match reachability checking but to test for the flow-sensitive analysis in typer. We should split the test into two, one that errors only in typer, and one that tests only match reachability checking. |
Here are the proposed two tests. Note that the second one needs to go in // Test flow-typing when NotNullInfos are from cases
object MatchTest {
def f6(s: String | Null): String = s match {
case s2 => s2 // error
case s3 => s3 // OK since not null
}
def f7(s: String | Null): String = s match {
case null => "other"
case s3 => s3 // OK since not null
}
} // Test unreachable matches in presence of nulls
object MatchTest2 {
def f6(s: String | Null): String = s match {
case s2 => s2.nn
case null => "other" // warn
case s3 => s3 // warn
}
def f7(s: String | Null): String = s match {
case null => "other"
case null => "other" // warn
case s3: String => s3
case s4 => s4.nn // warn
}
} |
@@ -0,0 +1,54 @@ | |||
//> using options -Xfatal-warnings |
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.
This should go in warn
instead of enabling fatal warnings.
da9ae84
to
3a0d79f
Compare
OK I think all the comments have been addressed, apologies for the delay. Please let me know if I missed something. |
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.
LGTM. @noti0na1 can you also have a look?
3a0d79f
to
297bed4
Compare
An up-to-date version of #19258 with merge conflicts resolved.