-
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
Chaining Java functions using -Yexplicit-nulls
and scala.language.unsafeNulls
fails compilation
#14592
Comments
this was actually fixed in #14523, (unreleased yet) we can add some regression tests |
@bishabosha I tried to search but I can see it is exactly the same issue as #14319 |
I'll add a test case to replicate the code, just so we cover more examples |
@bishabosha IMHO my examples looks like exact replicas of the example on the original test so this will just make the tests run slower with no added benefit. But it is up to you. |
The fix, to "thread context" correctly, puns on this example, |
The example I refer to is not from the PR but from issue #14319 which has this example: // -Yforce-sbt-phases -Yexplicit-nulls
import java.nio.file.FileSystems
def directorySeparator: String = {
import scala.language.unsafeNulls
FileSystems.getDefault().getSeparator()
} I would say that in the context of this bug, Do we really need another test? |
Duplicate of issue #14319. |
Compiler version
Scala 3.1.1
Minimized code
Compiling this code with compiler option
-Yexplicit-nulls
results in a compilation error:Output
The result of compiling the above code:
Expectation
The code should compile without error.
Additional comments
When compiling the above code, the compiler emits two errors. The error is only triggered when using compiler option
-Yexplicit-nulls
and also includingimport scala.language.unsafeNulls
in the scope of the lines that fail compilation.Any call to a Java function (returning
T | Null
for some typeT
) that is chained from a call to another Java function triggers this condition.Making a similar chain of functions using code defined in Scala, like in the code below, does not trigger the compiler error:
Adding explicit
.nn
calls in the failing code works around the bug – withimport scala.language.unsafeNulls
still in place.For example, this code compiles without error:
Another workaround is to split the chained calls as the bug is only triggered when chaining calls.
This code compiles:
The text was updated successfully, but these errors were encountered: