summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/transform/Mixin.scala
diff options
context:
space:
mode:
authorErik Osheim <d_m@plastic-idolatry.com>2012-05-14 00:13:16 -0400
committerErik Osheim <d_m@plastic-idolatry.com>2012-05-14 00:13:16 -0400
commitf7d5f45aa7d5b1977043aa169bf2cdb42f07a002 (patch)
tree82445a0574b8c233cf6b7f491ce5ca8eb88b3fad /src/compiler/scala/tools/nsc/transform/Mixin.scala
parent32a2068e3cc40ccab32f3c207cff73cfb6cc2ef5 (diff)
downloadscala-f7d5f45aa7d5b1977043aa169bf2cdb42f07a002.tar.gz
scala-f7d5f45aa7d5b1977043aa169bf2cdb42f07a002.tar.bz2
scala-f7d5f45aa7d5b1977043aa169bf2cdb42f07a002.zip
Specialize lazy vals (closes SI-5552)
Previously, specialized lazy vals would not work at all when used in specialized classes, and would just return an uninitialized value. After this patch, they work in the same way as other specialized fields do (i.e. a new specialized field is created, and the specialized class uses that instead of the base class' field). Note that there are still known problems with specialized lazy vals (for instance SI-4717) but it seemed to me that this was better than nothing.
Diffstat (limited to 'src/compiler/scala/tools/nsc/transform/Mixin.scala')
-rw-r--r--src/compiler/scala/tools/nsc/transform/Mixin.scala14
1 files changed, 7 insertions, 7 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/Mixin.scala b/src/compiler/scala/tools/nsc/transform/Mixin.scala
index 4ce5985af8..79b9317f20 100644
--- a/src/compiler/scala/tools/nsc/transform/Mixin.scala
+++ b/src/compiler/scala/tools/nsc/transform/Mixin.scala
@@ -903,14 +903,14 @@ abstract class Mixin extends InfoTransform with ast.TreeDSL {
if (sym.isLazy && !isEmpty && !clazz.isImplClass) {
assert(fieldOffset contains sym, sym)
- deriveDefDef(stat)(rhs =>
- if (isUnit)
- mkLazyDef(clazz, sym, List(rhs), UNIT, fieldOffset(sym))
- else {
- val Block(stats, res) = rhs
+ deriveDefDef(stat) {
+ case t if isUnit => mkLazyDef(clazz, sym, List(t), UNIT, fieldOffset(sym))
+
+ case Block(stats, res) =>
mkLazyDef(clazz, sym, stats, Select(This(clazz), res.symbol), fieldOffset(sym))
- }
- )
+
+ case t => t // pass specialized lazy vals through
+ }
}
else if (needsInitFlag(sym) && !isEmpty && !clazz.hasFlag(IMPLCLASS | TRAIT)) {
assert(fieldOffset contains sym, sym)