From f04257b8414745d8e13bee213e551ef01c839602 Mon Sep 17 00:00:00 2001 From: Jason Zaugg Date: Wed, 28 Aug 2013 15:51:49 +0200 Subject: SI-3832 Don't lift methods in aux constructor trailing stats as STATIC SI-1909 modified LambdaLift to lift in auxiliary constructors methods as STATIC so they could be called before the self-constructor was called. That allowed for: class Foo (x: Int) { def this() = this( { def bar() = 5 bar }) } However, if the method is in a statement that trails the self constructor call, this is unnecessary and in fact incorrect as it robs the lifted method of `this`. This commit uses the machinery established in SI-6666 to limit the STATIC-ness of lifted methods to those used in arguments for self-constructor calls. This is used exclusively; the `isAuxillaryConstructor` check wasn't the right way to solve this, as was seen by the regression it caused in SI-3832. A new test case shows that we can statically lift methods in super-constructor calls, rather than just self-constructor calls. We also have to avoid statically lifting objects in these positions. For now, I just emit a dev warning that a VerifyError is in your future. With some more thought we could escalate that to a implementation restriction and emit an error. --- test/files/neg/t1909-object.check | 4 ++++ test/files/neg/t1909-object.flags | 1 + test/files/neg/t1909-object.scala | 12 ++++++++++++ test/files/run/t1909c.scala | 9 +++++++++ test/files/run/t3832.scala | 17 +++++++++++++++++ 5 files changed, 43 insertions(+) create mode 100644 test/files/neg/t1909-object.check create mode 100644 test/files/neg/t1909-object.flags create mode 100644 test/files/neg/t1909-object.scala create mode 100644 test/files/run/t1909c.scala create mode 100644 test/files/run/t3832.scala (limited to 'test') diff --git a/test/files/neg/t1909-object.check b/test/files/neg/t1909-object.check new file mode 100644 index 0000000000..401c1f7ebf --- /dev/null +++ b/test/files/neg/t1909-object.check @@ -0,0 +1,4 @@ +t1909-object.scala:4: error: !!! SI-1909 Unable to STATICally lift object InnerTrouble$1, which is defined in the self- or super-constructor call of class Kaboom. A VerifyError is likely. + object InnerTrouble + ^ +one error found diff --git a/test/files/neg/t1909-object.flags b/test/files/neg/t1909-object.flags new file mode 100644 index 0000000000..eb8b40661b --- /dev/null +++ b/test/files/neg/t1909-object.flags @@ -0,0 +1 @@ +-Xdev -Xfatal-warnings \ No newline at end of file diff --git a/test/files/neg/t1909-object.scala b/test/files/neg/t1909-object.scala new file mode 100644 index 0000000000..d6011ba4a5 --- /dev/null +++ b/test/files/neg/t1909-object.scala @@ -0,0 +1,12 @@ +class Kaboom(a: Any) { + def this() = { + this({ + object InnerTrouble + InnerTrouble + }) + } +} + +object Test extends App { + new Kaboom() +} \ No newline at end of file diff --git a/test/files/run/t1909c.scala b/test/files/run/t1909c.scala new file mode 100644 index 0000000000..87c0eb08b5 --- /dev/null +++ b/test/files/run/t1909c.scala @@ -0,0 +1,9 @@ +class Base(a: Any) + +// java.lang.VerifyError: (class: Sub, method: signature: ()V) Expecting to find object/array on stack +// at Test$.(t1909c.scala) +class Sub() extends Base({ def bippy = 5; bippy }) + +object Test extends App { + new Sub() +} diff --git a/test/files/run/t3832.scala b/test/files/run/t3832.scala new file mode 100644 index 0000000000..ac44358bc7 --- /dev/null +++ b/test/files/run/t3832.scala @@ -0,0 +1,17 @@ +class t3832 { + def this(un: Int) = { + this() + def bippy = this + () + } + def this(un: Boolean) = { + this() + def boppy = () => this + () + } +} + +object Test extends App { + new t3832(0) + new t3832(true) +} -- cgit v1.2.3