Skip to content
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

$delayedInit$body.$outer is missing synthetic flag #9858

Open
scabug opened this issue Jul 12, 2016 · 4 comments
Open

$delayedInit$body.$outer is missing synthetic flag #9858

scabug opened this issue Jul 12, 2016 · 4 comments
Labels
Milestone

Comments

@scabug
Copy link

scabug commented Jul 12, 2016

When extending DelayedInit trait the field referencing to an outer class "$outer" in the generated "$delayedInit$body" is not marked as synthetic. At the same time for any normal usage of inner classes generated "$outer" field is marked as synthetic.

See: https://gist.github.com/pbadenski/982dc47e8636a0f706c7bf46d610574f

@scabug
Copy link
Author

scabug commented Jul 12, 2016

Imported From: https://issues.scala-lang.org/browse/SI-9858?orig=1
Reporter: pbadenski
Affected Versions: 2.11.8, 2.12.0-M5

@scabug
Copy link
Author

scabug commented Aug 17, 2016

Ausmarton Fernandes (ausmarton-at-gmail.com) said:
From Constructors.scala#L269 it looks like outerField is never given a SYNTHETIC flag. Also, looking a bit through the history of this Transformer, it doesn't seem to have ever been applying SYNTHETIC on that field unlike what you'd find in ExplicitOuter.

However, the syntax tree for the example provided seems to generate a <synthetic> Outer$delayedInit$body, which in turn contains the $outer which is not marked <synthetic> as shown below:

package <empty> {
  class Outer extends Object with DelayedInit {
    private[this] val code: scala.collection.mutable.ListBuffer = _;
    <stable> <accessor> private def code(): scala.collection.mutable.ListBuffer = Outer.this.code;
    override def delayedInit(body: Function0): Unit = {
      Outer.this.code().+=(body);
      ()
    };
    final <synthetic> def delayedEndpoint$Outer$1: Unit = {
      Outer.this.code = new scala.collection.mutable.ListBuffer();
      ()
    };
    def <init>(): Outer = {
      Outer.super.<init>();
      Outer.this.delayedInit(new Outer$delayedInit$body(Outer.this));
      ()
    }
  };
  final <synthetic> class Outer$delayedInit$body extends runtime.AbstractFunction0 {
    <paramaccessor> private[this] val $outer: Outer = _;
    final def apply(): Object = {
      Outer$delayedInit$body.this.$outer.delayedEndpoint$Outer$1();
      scala.runtime.BoxedUnit.UNIT
    };
    def <init>($outer: Outer): Outer$delayedInit$body = {
      if ($outer.eq(null))
        throw null
      else
        Outer$delayedInit$body.this.$outer = $outer;
      Outer$delayedInit$body.super.<init>();
      ()
    }
  }
}

@scabug
Copy link
Author

scabug commented Aug 17, 2016

@SethTisue said:
does the issue exist in 2.12.0-M5 as well?

@scabug
Copy link
Author

scabug commented Aug 17, 2016

Ausmarton Fernandes (ausmarton-at-gmail.com) said:
Yup, 2.12.0-M5 seems to produce a similar tree. From the git history, it looks like it's been this way at least since 2006-2007 (that's the farthest I looked).

Also, I tried adding a SYNTHETIC flag to the field in the transformer, which generates a tree like this one:

package <empty> {
  class Outer extends Object with DelayedInit {
    private[this] val code: scala.collection.mutable.ListBuffer = _;
    <stable> <accessor> private def code(): scala.collection.mutable.ListBuffer = Outer.this.code;
    override def delayedInit(body: Function0): Unit = {
      Outer.this.code().+=(body);
      ()
    };
    final <synthetic> def delayedEndpoint$Outer$1: Unit = {
      Outer.this.code = new scala.collection.mutable.ListBuffer();
      ()
    };
    def <init>(): Outer = {
      Outer.super.<init>();
      Outer.this.delayedInit(new Outer$delayedInit$body(Outer.this));
      ()
    }
  };
  final <synthetic> class Outer$delayedInit$body extends runtime.AbstractFunction0 {
    <synthetic> <paramaccessor> private[this] val $outer: Outer = _;
    final def apply(): Object = {
      Outer$delayedInit$body.this.$outer.delayedEndpoint$Outer$1();
      scala.runtime.BoxedUnit.UNIT
    };
    def <init>($outer: Outer): Outer$delayedInit$body = {
      if ($outer.eq(null))
        throw null
      else
        Outer$delayedInit$body.this.$outer = $outer;
      Outer$delayedInit$body.super.<init>();
      ()
    }
  }
}

However, I'm not sure having a <synthetic> inside a <synthetic> is valid/correct.

@scabug scabug added this to the Backlog milestone Apr 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants