diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2016-10-06 17:27:51 +1100 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2016-10-07 14:27:54 +1100 |
commit | ef14a9af16d988e6240c8a3943fa3df84ee42606 (patch) | |
tree | 6726a261e6e8a1ab2d9cee7b9053d915b0aa9908 /test | |
parent | 55c0581b476381fe66ff0df2ada44560f6511648 (diff) | |
download | scala-ef14a9af16d988e6240c8a3943fa3df84ee42606.tar.gz scala-ef14a9af16d988e6240c8a3943fa3df84ee42606.tar.bz2 scala-ef14a9af16d988e6240c8a3943fa3df84ee42606.zip |
SI-9946 don't null field in lazy accessors that turn out to be live
If a non-transient lazy val is the only user of a private field in
a class, the field is nulled out at the end of the lazy initializer.
This is tested in the existing test `run/lazy-leaks.scala`.
The analysis of which fields could be nulled out was recently moved
from `mixin` to the new `fields` phase. This introduced a regression
as a reference from an inner- or companion-classes had not yet
been processed by `explicitouter` to publicise private fields.
This commit delays the analysis to mixin (after explicit outer has
done its work.)
Navigating from `foo$lzycompute()` to `foo()` to `foo` is a little
dirty now. I'm not sure whether there is a more robust way to
structure things.
Diffstat (limited to 'test')
-rw-r--r-- | test/files/run/t9946b.scala | 12 | ||||
-rw-r--r-- | test/files/run/t9946c.scala | 10 |
2 files changed, 22 insertions, 0 deletions
diff --git a/test/files/run/t9946b.scala b/test/files/run/t9946b.scala new file mode 100644 index 0000000000..ac102a38f7 --- /dev/null +++ b/test/files/run/t9946b.scala @@ -0,0 +1,12 @@ +class Test(private val x: String) { + lazy val y = x.reverse +} +object Test { + def getX(t: Test) = t.x + def main(args: Array[String]): Unit = { + val t = new Test("foo") + assert(t.y == "oof", t.y) + assert(t.x == "foo", t.x) + } +} + diff --git a/test/files/run/t9946c.scala b/test/files/run/t9946c.scala new file mode 100644 index 0000000000..f9fe68d48f --- /dev/null +++ b/test/files/run/t9946c.scala @@ -0,0 +1,10 @@ +class Test(private[this] val x: String) { + lazy val y = x.reverse +} +object Test { + def main(args: Array[String]): Unit = { + val t = new Test("foo") + assert(t.y == "oof", t.y) + } +} + |