bug icon indicating copy to clipboard operation
bug copied to clipboard

Mixed compilation: cannot refer to Scala object in Java source

Open scabug opened this issue 9 years ago • 1 comments
trafficstars

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

scabug avatar Mar 23 '16 08:03 scabug

Imported From: https://issues.scala-lang.org/browse/SI-9714?orig=1 Reporter: @lrytz Affected Versions: 2.11.7

scabug avatar Mar 23 '16 08:03 scabug

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?"

SethTisue avatar Dec 23 '23 21:12 SethTisue

Yes,I think the code should be O.type

He-Pin avatar Dec 23 '23 21:12 He-Pin

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.

som-snytt avatar Dec 26 '23 21:12 som-snytt

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.

SethTisue avatar Dec 28 '23 17:12 SethTisue

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.

som-snytt avatar Dec 28 '23 20:12 som-snytt