Skip to content
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

extractAPI fails with unsafeNulls and Yexplicit-nulls #14319

Closed
bishabosha opened this issue Jan 21, 2022 · 2 comments · Fixed by #14523
Closed

extractAPI fails with unsafeNulls and Yexplicit-nulls #14319

bishabosha opened this issue Jan 21, 2022 · 2 comments · Fixed by #14523

Comments

@bishabosha
Copy link
Member

Compiler version

3.1.0

Minimized code

// -Yforce-sbt-phases -Yexplicit-nulls
import java.nio.file.FileSystems

def directorySeparator: String = {
  import scala.language.unsafeNulls
  FileSystems.getDefault().getSeparator()
}

Output

-- Error: foo.scala:5:39 -------------------------------------------------------
5 |  FileSystems.getDefault().getSeparator()
  |  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |undefined: java.nio.file.FileSystems.getDefault().getSeparator # -1: TermRef(OrType(TypeRef(ThisType(TypeRef(NoPrefix,module class file)),class FileSystem),TypeRef(ThisType(TypeRef(NoPrefix,module class scala)),class Null)),getSeparator) at sbt-api
1 error found

Expectation

extractAPI maybe ignores this?

@noti0na1
Copy link
Member

noti0na1 commented Jan 21, 2022

I think this issue is similar to #13976: the imported language feature is not avaiable after typer (there is no error if we enable the unsafeNulls globally using -language:unsafeNulls).

When we transform FileSystems.getDefault().getSeparator in PostTyper, the type of FileSystems.getDefault() is nullable. We will get wrong type at .getSeparator because unsafeNulls is not visible at this phase.

We can always add a special attachment to the tree in typer if needed. I'm wondering if there is a better and general solution.

@olhotak
Copy link
Contributor

olhotak commented Jan 25, 2022

See #14346 for a sketch of a general solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment