Skip to content

inner trait in method does not get outer reference if needs to access outer object #503

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
DarkDimius opened this issue Apr 28, 2015 · 0 comments

Comments

@DarkDimius
Copy link
Contributor

./tests/pos/t1237.scala

class HelloWorld {
  def main(args: Array[String]): Unit = {
    object TypeBool;

    trait Fct {
      def g(x : Int) = TypeBool // breaks.
    }
  }
}

result of A2.scala after TreeTransform:{patternMatcher, explicitOuter, splitter}:
  class HelloWorld() extends Object() {
    def main(args: Array[String]): Unit = {
      final lazy module val TypeBool: TypeBool$ = new TypeBool$()
      final module class TypeBool$() extends Object() { this: TypeBool.type =>}
      <trait> trait Fct() extends Object {
        def g(x: Int): TypeBool$ = TypeBool
      }
      ()
    }
  }

trait Fct references TypeBool(), a getter that will be lifted to HelloWorld(with environment added, but still).

If one replaced object TypeBool by def it works.

class HelloWorld() extends Object() {
    def main(args: Array[String]): Unit = {
      def TypeBool: HelloWorld = this
      <trait> trait Fct() extends Object() {
        def g(x: Int): HelloWorld = TypeBool
        final def HelloWorld$$Fct$$$outer: HelloWorld
      }
      final lazy module val Fct: Fct$ = new Fct$()
      final module class Fct$() extends Object() { this: Fct.type =>}
      ()
    }
  }
@DarkDimius DarkDimius changed the title inner in method trait does not get outer reference if needs to access outer object inner trait in method does not get outer reference if needs to access outer object Apr 28, 2015
DarkDimius added a commit to dotty-staging/dotty that referenced this issue Apr 28, 2015
DarkDimius added a commit to dotty-staging/dotty that referenced this issue Apr 28, 2015
DarkDimius added a commit to dotty-staging/dotty that referenced this issue Apr 30, 2015
odersky added a commit to dotty-staging/dotty that referenced this issue May 4, 2015
Previously, we considered only methods. scala#503 shows that this is wrong.
odersky added a commit to dotty-staging/dotty that referenced this issue May 4, 2015
Added test for previous PR on super accessors.
Updated test for scala#503 to check both inner classes and inner traits.
DarkDimius added a commit that referenced this issue May 4, 2015
@odersky odersky closed this as completed May 15, 2015
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