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

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

Open
scabug opened this issue Aug 2, 2014 · 2 comments

Comments

@scabug
Copy link

scabug commented Aug 2, 2014

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.

@scabug
Copy link
Author

scabug commented Aug 2, 2014

Imported From: https://issues.scala-lang.org/browse/SI-8775?orig=1
Reporter: @retronym
Affected Versions: 2.11.0
See #6666

@scabug
Copy link
Author

scabug commented Jan 24, 2016

Li Haoyi (lihaoyi) said:
Here's another case out in the wild:

Original issue: com-lihaoyi/upickle#108

Minimal Repro:

haoyi-mbp:test haoyi$ cat build.sbt
scalaVersion := "2.11.7"

haoyi-mbp:test haoyi$ cat Main.scala
object Main{
  abstract class TakesWriter()(implicit i: Int)
  class Something extends TakesWriter()({
    lazy val derive$macro$1 = (() => derive$macro$2)
    lazy val derive$macro$2 = 2
    1
  })
}

haoyi-mbp:test haoyi$ sbt ~run
<sbt spam>

[info] Compiling 1 Scala source to /Users/haoyi/Dropbox (Personal)/Workspace/test/target/scala-2.11/classes...
[error] /Users/haoyi/Dropbox (Personal)/Workspace/test/Main.scala:4: Implementation restriction: access of value derive$macro$2$1 from <$anon: Function0>, would require illegal premature access to the unconstructed `this` of class Something in object Main
[error]     lazy val derive$macro$1 = (() => derive$macro$2)
[error]                                      ^
[error] one error found
[error] (compile:compile) Compilation failed

@scabug scabug added this to the Backlog milestone Apr 7, 2017
@SethTisue SethTisue changed the title Spurious warnings for "premature access to this" (SI-6666) for static-ally lamda-lifted def in pre-super position Spurious warnings for "premature access to this" (SI-6666) for static-ally lambda-lifted def in pre-super position Nov 21, 2019
@pabloazul pabloazul removed this from the Backlog milestone Nov 21, 2019
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

3 participants