-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Companion object cannot be found from Java in Scala 3, but it compiles in Scala 2.x. #17255
Comments
seems similar to scala/scala#10644 (by @som-snytt) — though that PR won't ship until 2.13.13. @i10416 did you test 2.13.12, or a nightly? |
I tested the following versions and with Scala 2.x, it compiles with CompileOrder.Mixed, while it does not with 3.x. I didn't tested Scala 2.13.12 nor 3.3.1.
scala/scala#10644 seems so similar to this issue that we could derive some hints from it. I'll look into the cnanges in 10644. |
By the way, 10644 is forward ported to Scala 3? |
That is not forward-ported yet. The current difference may be that there is no reason to typecheck a private element in Java. |
To find Scala companion mudule from Java, we should strip module suffix `$`. This provides workaround for scala#17255, but it requires some refinment to fully fix it because not-fully-qualified type like the following example still fails to compile due to missing symbol. ```java package example; public class Bar { private static final Foo$ MOD = Foo$.MODULE; } ``` This is because `pre` in `javaFindMember` for `Foo` in the case above is `<root>`, not `example` and therefore `pre.findMember` looks for `<root>.Foo` instead of `example.Foo`. I'm not sure whether the qualifier is intentionally dropped.
To find Scala companion mudule from Java, we should strip module suffix `$`. This provides workaround for scala#17255, but it requires some refinment to fully fix it because not-fully-qualified type like the following example still fails to compile due to missing symbol. ```java package example; public class Bar { private static final Foo$ MOD = Foo$.MODULE; } ``` This is because `pre` in `javaFindMember` for `Foo` in the case above is `<root>`, not `example` and therefore `pre.findMember` looks for `<root>.Foo` instead of `example.Foo`. I'm not sure whether the qualifier is intentionally dropped.
To find Scala companion mudule from Java, we should strip module suffix `$`. This provides workaround for scala#17255, but it requires some refinment to fully fix it because not-fully-qualified type like the following example still fails to compile due to missing symbol. ```java package example; public class Bar { private static final Foo$ MOD = Foo$.MODULE; } ``` This is because `pre` in `javaFindMember` for `Foo` in the case above is `<root>`, not `example` and therefore `pre.findMember` looks for `<root>.Foo` instead of `example.Foo`. I'm not sure whether the qualifier is intentionally dropped.
To find Scala companion mudule from Java in mixed sources, we should strip module suffix `$`. This provides workaround for scala#17255, but it requires some refinment to fix it because not-fully-qualified type like the following example still fails to compile due to missing symbol. ```java package example; public class Bar { private static final Foo$ MOD = Foo$.MODULE; } ``` This is because `pre` in `javaFindMember` for `Foo` in the case above is `<root>`, not `example` and therefore `pre.findMember` looks for `<root>.Foo` instead of `example.Foo`. I'm not sure whether the qualifier is intentionally dropped. References - scala#12884 - scala/scala#7671
To find Scala companion mudule from Java, we should strip module suffix `$`. This ~provides workaround~ fixes #17255 as well as forward-port scala/scala#10644. ~, but it requires some refinment to fix it because not-fully-qualified type like the following example still fails to compile due to missing symbol.~ Related to scala/scala#10644
To find Scala companion mudule from Java in mixed sources, we should strip module suffix `$`. This provides workaround for #17255, but it requires some refinment to fix it because not-fully-qualified type like the following example still fails to compile due to missing symbol. ```java package example; public class Bar { private static final Foo$ MOD = Foo$.MODULE; } ``` This is because `pre` in `javaFindMember` for `Foo` in the case above is `<root>`, not `example` and therefore `pre.findMember` looks for `<root>.Foo` instead of `example.Foo`. I'm not sure whether the qualifier is intentionally dropped. References - #12884 - scala/scala#7671 [Cherry-picked 22d98d6][modified]
Compiler version
3.0.2, 3.1.3, 3.2.2, 3.3.0-RC3
Minimized code
https://github.com/i10416/reproduce-missing-symbol-error-in-scala-3
The following code compiles in Scala 2.x, but won't compile in Scala 3.x for "Not found: type Foo".
src/main/java/Bar.java
src/main/scala/Foo.scala
Output
Expectation
It should compile. Or is this expected behavior?
Note
It compiles in Scala 3 when you explicitly specify
compileOrder := CompileOrder.ScalaThenJava
. However, if there are both Scala code depending on Java and Java code depending Scala, you have no choice butCompileOrder.Mixed
.Notably, even if there are both Scala code depending on Java and Java code depending Scala, Scala 2.x can compile them (in CompileOrder.Mixed mode).
The text was updated successfully, but these errors were encountered: