bug
bug copied to clipboard
Mixed compilation: cannot refer to Scala object in Java source
Test.scala
package p
object O {
Test.foo()
}
Test.java
package p;
public class Test {
public static p.O$ foo() { return null; }
}
$ rm -rf p && scalac11 Test.scala Test.java
Test.java:3: error: not found: type p
public static p.O$ foo() { return null; }
^
one error found
Imported From: https://issues.scala-lang.org/browse/SI-9714?orig=1 Reporter: @lrytz Affected Versions: 2.11.7
remains reproducible in both Scala 2.13.12 and 3.3.1. The 3.3.1 error message is "type O is not a member of p - did you mean p.O.type?"
Yes,I think the code should be O.type
To review, javac is happy because public static final p.Module$ MODULE$; but scalac doesn't understand what is intended by p.Module$ in Java source.
The PR says OK, when we translate Java statics, also translate the lookup of Module$ names as type names (to a lookup of the corresponding term, returning its moduleClass).
Before Seth says, "Did you intend to port it to Scala 3?", the answer is a definite maybe.
I'm okay with going ahead with a fix in Scala 2 regardless, on the grounds that 1) it's a fix, not a design change, and 2) forward-porting should present no special difficulties to an interested contributor, even if that contributor isn't you.
I am a disinterested contributor.
It's important that we get the fix into 2.13.13 because Lukas has a test that's been waiting for 8 years.