scala / bug

Scala 2 bug reports only. Please, no questions — proper bug reports only.
https://scala-lang.org
232 stars 21 forks source link

Scala believes that Java has dependent types under joint compilation #11569

Open retronym opened 5 years ago

retronym commented 5 years ago

The following is legal Java code

public class C {
    public final class Inner {
      public void use(Inner i) {}
    }

    public void use(Inner i) {};

    private static void javaClient() {
       C c1 = new C();
       C c2 = new C();
       Inner i1 = c1.new Inner();
       Inner i2 = c2.new Inner();
       // javac doesn't track the outer instance in the types
       c1.use(i1);
       c1.use(i2);
       i1.use(i1);
       i1.use(i2);
    }
}

Analogous client code from Scala fails to compile jointly.

class Client {
    def client() {
      val c1 = new C
      val c2 = new C
      val i1 = new c1.Inner
      val i2 = new c2.Inner
      c1.use(i1)
      c1.use(i2)
      i1.use(i1);
      i1.use(i2);
    }
}
retronym commented 5 years ago

I noticed this when testing Spark under pipelined compilation with -Ypickle-java.

We might be able to fix this by extending cookJavaRawTypes to map instanceOfOuter.Inner to Outer#Inner.