Skip to content

Spurious warnings for "premature access to this" (SI-6666) for static-ally lambda-lifted def in pre-super position #8775

@scabug

Description

@scabug
qscalac -Xprint:lambdalift sandbox/test.scala
sandbox/test.scala:2: error: Implementation restriction: access of method x$1 in class Bar from class C$1, would require illegal premature access to the unconstructed `this` of class Bar
class Bar extends Foo({ def x = 1; class C { x } })
                                             ^
[[syntax trees at end of                lambdalift]] // test.scala
package <empty> {
  class Foo extends Object {
    <paramaccessor> private[this] val foo: Object = _;
    def <init>(foo: Object): Foo = {
      Foo.super.<init>();
      ()
    }
  };
  class Bar extends Foo {
    def <init>(): Bar = {
      Bar.super.<init>({
        scala.runtime.BoxedUnit.UNIT
      });
      ()
    };
    final <static> def x$1(): Int = 1;
    class C$1 extends Object {
      def <init>(): Bar#C$1 = {
        C$1.super.<init>();
        ()
      };
      <empty>.x$1()
    }
  }
}

one error found

Given that lambda-lift makes def x a static member of the enclosing class (which is done in a last-gasp attempt), this warning is spurious.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions