Skip to content

$outer of trait not implemented if the class doesn't need $outer #1820

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
liufengyun opened this issue Dec 17, 2016 · 1 comment
Closed

$outer of trait not implemented if the class doesn't need $outer #1820

liufengyun opened this issue Dec 17, 2016 · 1 comment

Comments

@liufengyun
Copy link
Contributor

Following code runs in Scalac, but failed to run in Dotty. Inspecting the generated code shows that the $outer for A.Inner is not implemented in the top-leve class Inner.

class A {
  val a = "a"
  trait Inner {
    def f = println(a)
    def h = 3
  }
}

class Inner extends O.a.Inner

object O {
  val a = new A

  def main(args: Array[String]): Unit = {
    (new Inner).f
  }
}

A fix is in order, will push soon.

@liufengyun liufengyun self-assigned this Dec 17, 2016
liufengyun added a commit to dotty-staging/dotty that referenced this issue Dec 17, 2016
liufengyun added a commit to dotty-staging/dotty that referenced this issue Dec 19, 2016
Previously, we don't generate `outer` for the annoymous class `Inner3`,
because it doesn't reference the symbol `B`.

This is incorrect, as `Inner3` extends `A`, which requires an outer.

trait A {
  val a = "a"
  trait Inner {
    def f = println(a)
    def h = 3
  }
}

trait B extends A {
  trait Inner2 extends Inner
  class Inner3 extends Inner2
}
@liufengyun
Copy link
Contributor Author

liufengyun commented Dec 19, 2016

Fixing the above issue expose another issue about $outer.

We should generate an $outer for the anonymous class new Inner2 {}, as Inner requires an outer. But currently we don't. The latest commit 72bbc30 fix this problem.

trait A {
  val a = "a"
  trait Inner {
    def f = println(a)
    def h = 3
  }
}

trait B extends A {
  trait Inner2 extends Inner
  new Inner2 {}
}

liufengyun added a commit to dotty-staging/dotty that referenced this issue Dec 19, 2016
Previously, we don't generate `outer` for the class `Inner3`,
because it doesn't reference the symbol `B`.

This is incorrect, as `Inner3` extends `A.Inner`, which requires an outer.

trait A {
  val a = "a"
  trait Inner {
    def f = println(a)
    def h = 3
  }
}

trait B extends A {
  trait Inner2 extends Inner
  class Inner3 extends Inner2
}
liufengyun added a commit to dotty-staging/dotty that referenced this issue Dec 19, 2016
Previously, we don't generate `outer` for the anonymous class `new Inner2 {}`.
This is incorrect, as `Inner2 {}` extends `A.Inner`, which requires an outer.

trait A {
  val a = "a"
  trait Inner {
    def f = println(a)
    def h = 3
  }
}

trait B extends A {
  trait Inner2 extends Inner
  new Inner2 {}
}
odersky added a commit that referenced this issue Dec 20, 2016
Fix #1820: make sure outer of traits implemented
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