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
3.2.0-RC1-bin-20220308-29073f1-NIGHTLY with -Yexplicit-nulls
Minimized code
scala>valSplit="([^#]+)?(?:#(.+)?)?".r
valSplit: scala.util.matching.Regex= ([^#]+)?(?:#(.+)?)?
scala>"#foo"match|caseSplit(pre, _) if pre !=null=> println(s"pre=$pre")
|case _ => println("no match")
|--Error:----------------------------------------------------------------------2|caseSplit(pre, _) if pre !=null=> println(s"pre=$pre")
|^^^^^^^^^^^|Values of types String and Null cannot be compared with== or !=1 error found
But I don't think we can modify the type of standard library easily.
I think a PR to https://github.com/scala/scala/ that added @Nullable annotations where needed in the standard library could be accepted. Though I guess the annoying part here is that we'd need to create yet another Nullable annotation since scala-library doesn't define one and can't start depending on other jars.
We could have a @CanEqualNull annotation that allows an expression of a non-null type to be compared against null. We could use it in two places:
In the Scala standard library to annotate types of methods such as scala.util.matching.Regex.unapplySeq without breaking binary compatibility.
A new language.unsafeJava scope that assigns non-null return types to calls to Java-defined methods. Such a scope would allow member accesses on values returned from Java, but would normally break == null comparison for such values. A @CanEqualNull annotation would fix the latter problem.
Compiler version
3.2.0-RC1-bin-20220308-29073f1-NIGHTLY with
-Yexplicit-nulls
Minimized code
but removing the guard gives:
Output
As shown above
Expectation
pre
is typed asString | Null
Notes
I suspect this is due to #7871?
Is there anything I can do here besides locally importing
language.unsafeNulls
?The text was updated successfully, but these errors were encountered: