Skip to content

casting covariant type with Nothing fails in java #8936

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

Closed
martijnhoekstra opened this issue May 10, 2020 · 3 comments · Fixed by #8943
Closed

casting covariant type with Nothing fails in java #8936

martijnhoekstra opened this issue May 10, 2020 · 3 comments · Fixed by #8943

Comments

@martijnhoekstra
Copy link
Contributor

Minimized code

class Example {
  def no: List[Nothing] = Nil
}
import scala.collection.immutable.List;

class Javaisms {
  void Nothingness(){
    Example ex = new Example();
    List<String> strings = (List<String>)ex.no();
  } 
}

Output

[info] Compiling 1 Scala source and 1 Java source to /home/martijn/experiment/mimi/target/scala-0.24/classes ...
[error] /home/martijn/experiment/mimi/src/main/java/Javaisms.java:6:1: cannot access scala.runtime.Nothing
[error]   class file for scala.runtime.Nothing not found
[error] (List<String>)ex.no()

Expectation

Compilation succeeds

@OlivierBlanvillain
Copy link
Contributor

Does this work with scalac?

@martijnhoekstra
Copy link
Contributor Author

Yes.

@smarter
Copy link
Member

smarter commented May 11, 2020

[error] class file for scala.runtime.Nothing not found

It needs to be scala.runtime.Nothing$ instead: https://github.com/scala/scala/blob/2.13.x/src/library/scala/runtime/Nothing%24.scala

smarter added a commit to dotty-staging/dotty that referenced this issue May 11, 2020
The runtime classes are called "scala.runtime.Nothing$" and
"scala.runtime.Null$", but the signatures were missing the dollar at the
end. Since these two types are special anyway, we can just emit their
signature directly and not bother with loading their classfiles.
smarter added a commit to dotty-staging/dotty that referenced this issue May 11, 2020
The runtime classes are called "scala.runtime.Nothing$" and
"scala.runtime.Null$", but the signatures were missing the dollar at the
end. Since these two types are special anyway, we can just emit their
signature directly and not bother with loading their classfiles.
@nicolasstucki nicolasstucki linked a pull request May 11, 2020 that will close this issue
OlivierBlanvillain added a commit that referenced this issue May 18, 2020
Fix #8936: Correct generic signature for Nothing/Null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants