summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukas Rytz <lukas.rytz@gmail.com>2016-09-27 08:05:47 +0200
committerLukas Rytz <lukas.rytz@gmail.com>2016-09-28 10:18:15 +0200
commitad6bf3033fbdbd1d2c8bdea245f8347cfe292c1b (patch)
tree7731dbe7c1216e2aab8f3b00f6c94e750386b194
parent19f6209e5b1db295320bfbd3ef00eeaa729c1eec (diff)
downloadscala-ad6bf3033fbdbd1d2c8bdea245f8347cfe292c1b.tar.gz
scala-ad6bf3033fbdbd1d2c8bdea245f8347cfe292c1b.tar.bz2
scala-ad6bf3033fbdbd1d2c8bdea245f8347cfe292c1b.zip
SI-4683 fix $outer accesses in class bodies extending DelayedInit
Constructors rewrites references to parameter accessor methods in the constructor to references to parameters. It avoids doing so for subclasses of DelayedInit. This commit makes sure the rewrite does not happen for the $outer paramter, a case that was simply forgotten.
-rw-r--r--src/compiler/scala/tools/nsc/transform/Constructors.scala2
-rw-r--r--test/files/run/t9697.check2
-rw-r--r--test/files/run/t9697.scala77
3 files changed, 79 insertions, 2 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/Constructors.scala b/src/compiler/scala/tools/nsc/transform/Constructors.scala
index 8d362f13dd..daf645fd20 100644
--- a/src/compiler/scala/tools/nsc/transform/Constructors.scala
+++ b/src/compiler/scala/tools/nsc/transform/Constructors.scala
@@ -527,7 +527,7 @@ abstract class Constructors extends Statics with Transform with TypingTransforme
super.transform(tree)
else if (canBeSupplanted(tree.symbol))
gen.mkAttributedIdent(parameter(tree.symbol)) setPos tree.pos
- else if (tree.symbol.outerSource == clazz)
+ else if (tree.symbol.outerSource == clazz && !isDelayedInitSubclass)
gen.mkAttributedIdent(parameterNamed(nme.OUTER)) setPos tree.pos
else
super.transform(tree)
diff --git a/test/files/run/t9697.check b/test/files/run/t9697.check
index bbd9fd19cf..2a4f01c14f 100644
--- a/test/files/run/t9697.check
+++ b/test/files/run/t9697.check
@@ -1 +1 @@
-warning: there were 6 deprecation warnings (since 2.11.0); re-run with -deprecation for details
+warning: there were 9 deprecation warnings (since 2.11.0); re-run with -deprecation for details
diff --git a/test/files/run/t9697.scala b/test/files/run/t9697.scala
index b837feb237..eb8e44f8fc 100644
--- a/test/files/run/t9697.scala
+++ b/test/files/run/t9697.scala
@@ -101,6 +101,57 @@ package t4683d {
}
}
+package t4683e {
+ class DelayedInitTest {
+ def a = log("uh")
+ class B extends DelayedInit {
+ a
+ def delayedInit(body: => Unit): Unit = body
+ }
+ }
+}
+
+package t4683f {
+ class Foo extends DelayedInit {
+ log("fooInit")
+ def delayedInit(newBody: => Unit): Unit = {
+ log("delayedInit")
+ inits = {
+ val f = () => newBody
+ if (inits == null) {
+ log("initsNull")
+ List(f)
+ } else
+ f :: inits
+ }
+ }
+ def foo = log("foo")
+ var inits: List[() => Unit] = Nil
+ }
+
+ class Bar extends Foo {
+ log("barInit")
+ def bar = foo
+ def newBaz: Foo = new Baz
+ private class Baz extends Foo {
+ log("bazInit")
+ bar
+ }
+ }
+}
+
+package t4683g {
+ trait MatExpWorld { self =>
+ class T extends Runner { val expWorld: self.type = self }
+ }
+
+ trait Runner extends DelayedInit {
+ def delayedInit(init: => Unit): Unit = init
+ val expWorld: MatExpWorld
+ }
+}
+
+
object Test extends App {
new t9697.C()
log.check("1234")
@@ -124,4 +175,30 @@ object Test extends App {
new t4683d.Injector().test
log.check("k")
+
+ val dit = new t4683e.DelayedInitTest()
+ new dit.B()
+ log.check("uh")
+
+ val fuu = new t4683f.Foo
+ log.check("delayedInitinitsNull")
+ fuu.inits.foreach(_.apply())
+ log.check("fooInit")
+ assert(fuu.inits == Nil) // the (delayed) initializer of Foo sets the inits field to Nil
+
+ val brr = new t4683f.Bar
+ log.check("delayedInitinitsNulldelayedInit") // delayedInit is called once for each constructor
+ brr.inits.foreach(_.apply())
+ log.check("barInitfooInit")
+ assert(brr.inits == Nil)
+
+ val bzz = brr.newBaz
+ log.check("delayedInitinitsNulldelayedInit")
+ bzz.inits.foreach(_.apply())
+ log.check("bazInitfoofooInit")
+ assert(bzz.inits == Nil)
+
+ val mew = new t4683g.MatExpWorld { }
+ val mt = new mew.T
+ assert(mt.expWorld == mew)
}