bug icon indicating copy to clipboard operation
bug copied to clipboard

In Java compilation units, references to inner classes are not properly qualified

Open lrytz opened this issue 3 years ago • 0 comments

Java 16+ (before that, inner classes like U below were not allowed to declare static members. the restrictions were lifted as part of https://openjdk.java.net/jeps/395).

public class C {
  public class U { public static class A {} }
  public void u(U.A a) {}
}

Scala:

class A {
  val c = new C()
  c.u(new c.U.A())
}

mixed compilation leads to

A.scala:8: error: type mismatch;
 found   : A.this.c.U.A
 required: U.A
  c.u(new c.U.A())
      ^
1 error

The reason is this change here: https://github.com/scala/scala/pull/7671/files#diff-334a019606bce49aa3cb747735d76c2c327c883f1f8f07a0dc65f072243341ebR1260, unit.isJava is too coarse.

The Ident(U) tree in the parameter type U.A remains an Ident, but should be come a Select(C.this, U).

Removing that the isJava condition breaks the java-inherited-type test. In the lookup of Outer.StaticInner, the prefix (pre0 in finishDefSym) is a type ref to the ModuleClass OuterBase, which fails in mkAttributedQualifier. In this case, no qualifier is fine because everything is static, but Outer could be non-static, and then a qualifier would be required (not sure which qualifier though...).

lrytz avatar Jun 09 '22 11:06 lrytz