Skip to content

ExplicitOuter doesn't match Scala 2.12's outer types #4342

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
gsps opened this issue Apr 19, 2018 · 2 comments
Closed

ExplicitOuter doesn't match Scala 2.12's outer types #4342

gsps opened this issue Apr 19, 2018 · 2 comments

Comments

@gsps
Copy link
Contributor

gsps commented Apr 19, 2018

Scala 2.12 appears to use the declared self type of the enclosing class as the outer type when transforming inner classes. Dotty doesn't match this behavior and uses the enclosing class itself, leading to NoSuchMethodErrors wrt. Scala 2.12 classes upon executing the Dotty-compiled code. Here's a minimal example:

Consider the following code, compiled with 2.12:

package foo

class A extends B

trait B { this: A =>
  class C
}

object a extends A

and the following code, compiled with Dotty:

object Scala2_12FromDotty {
  new foo.a.C  // runtime error: trying to call constructor of C with a B instead of an A
}

We can see the discrepancy in the generated code. That is, javap -p 'target/scala-2.12/classes/foo/B$C.class' yields:

Compiled from "Foo.scala"
public class foo.B$C {
  public final foo.A $outer;
  public foo.A foo$B$C$$$outer();
  public foo.B$C(foo.A);
}

whereas javap -c Scala2_12FromDotty$.class yields

Compiled from "Scala2_12FromDotty.scala"
public final class Scala2_12FromDotty$ {
  (...)
  public Scala2_12FromDotty$();
    Code:
      (...)
      12: getstatic     #25                 // Field foo/a$.MODULE$:Lfoo/a$;
      15: invokespecial #28                 // Method foo/B$C."<init>":(Lfoo/B;)V
      (...)
}

I tried to look into the related phases a bit, but I'm not sure whether this should be fixed in ExplicitOuter or by transforming infos, applications and defdefs later, for instance, as an extension of LinkScala2Impls.

@smarter
Copy link
Member

smarter commented Apr 19, 2018

I don't have much knowledge of the relevant code here, but this looks similar to what https://github.com/lampepfl/dotty/blob/2212dc0ea072614fabda1004d9cbb23401cba351/compiler/src/dotty/tools/dotc/transform/LinkScala2Impls.scala#L51-L52 tries to address.

@smarter smarter removed their assignment Apr 19, 2018
@gsps
Copy link
Contributor Author

gsps commented Apr 19, 2018

@smarter Yeah, I was looking at that part. I'll just take a stab at it, then.

gsps added a commit to gsps/dotty that referenced this issue Apr 19, 2018
gsps added a commit to gsps/dotty that referenced this issue Apr 20, 2018
…er, adapt to the old behavior in picking the outer parameter's type, i.e., prefer the enclosing class's self type, rather than the enclosing class itself.
gsps added a commit to gsps/dotty that referenced this issue Apr 20, 2018
gsps added a commit to gsps/dotty that referenced this issue Apr 20, 2018
gsps added a commit to gsps/dotty that referenced this issue Apr 20, 2018
gsps added a commit to gsps/dotty that referenced this issue Apr 20, 2018
gsps added a commit to gsps/dotty that referenced this issue Apr 21, 2018
gsps added a commit to gsps/dotty that referenced this issue Apr 21, 2018
gsps added a commit to gsps/dotty that referenced this issue Apr 21, 2018
gsps added a commit to gsps/dotty that referenced this issue Apr 21, 2018
gsps added a commit to gsps/dotty that referenced this issue Apr 21, 2018
…er, adapt to the old behavior in picking the outer parameter's type, i.e., prefer the enclosing class's self type, rather than the enclosing class itself.
smarter pushed a commit to dotty-staging/dotty that referenced this issue Jan 26, 2019
…er, adapt to the old behavior in picking the outer parameter's type, i.e., prefer the enclosing class's self type, rather than the enclosing class itself.
smarter added a commit that referenced this issue Jan 26, 2019
Fix #4342: Handle Scala2 method calls with an outer param
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants