diff options
author | Iulian Dragos <jaguarul@gmail.com> | 2007-11-15 15:07:48 +0000 |
---|---|---|
committer | Iulian Dragos <jaguarul@gmail.com> | 2007-11-15 15:07:48 +0000 |
commit | 8fc8fb71ac8df99e06c0c64986d6b4922d902d16 (patch) | |
tree | f6ab00b047dc57d8d03f5192865e9d3026d1706f /src/compiler/scala/tools/nsc/typechecker/RefChecks.scala | |
parent | ac791fa286be5496dc1f54c8bfaa46ece48b0ddd (diff) | |
download | scala-8fc8fb71ac8df99e06c0c64986d6b4922d902d16.tar.gz scala-8fc8fb71ac8df99e06c0c64986d6b4922d902d16.tar.bz2 scala-8fc8fb71ac8df99e06c0c64986d6b4922d902d16.zip |
Fixed ticket #206
Diffstat (limited to 'src/compiler/scala/tools/nsc/typechecker/RefChecks.scala')
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/RefChecks.scala | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala index ffecaf5a39..1eae1b9389 100644 --- a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala +++ b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala @@ -587,7 +587,8 @@ abstract class RefChecks extends InfoTransform { } /** Implements lazy value accessors: - * - for lazy fields inside traits, the rhs is the initializer itself + * - for lazy values of type Unit and all lazy fields inside traits, + * the rhs is the initializer itself * - for all other lazy values z the accessor is a block of this form: * { z = <rhs>; z } where z can be an identifier or a field. */ @@ -666,17 +667,22 @@ abstract class RefChecks extends InfoTransform { if (tree.symbol.hasFlag(LAZY)) { assert(tree.symbol.isTerm, tree.symbol) val vsym = tree.symbol + val hasUnitType = (tree.symbol.tpe.typeSymbol == definitions.UnitClass) val lazyDefSym = vsym.lazyAccessor assert(lazyDefSym != NoSymbol, vsym) val ownerTransformer = new ChangeOwnerTraverser(vsym, lazyDefSym) val lazyDef = atPos(tree.pos)( DefDef(lazyDefSym, vparamss => ownerTransformer( - if (tree.symbol.owner.isTrait) rhs // for traits, this is further tranformed in mixins + if (tree.symbol.owner.isTrait // for traits, this is further tranformed in mixins + || hasUnitType) rhs else Block(List( Assign(gen.mkAttributedRef(vsym), rhs)), gen.mkAttributedRef(vsym))))) log("Made lazy def: " + lazyDef) - typed(ValDef(vsym, EmptyTree)) :: typed(lazyDef) :: Nil + if (hasUnitType) + typed(lazyDef) :: Nil + else + typed(ValDef(vsym, EmptyTree)) :: typed(lazyDef) :: Nil } else { if (tree.symbol.isLocal && index <= currentLevel.maxindex && !tree.symbol.hasFlag(LAZY)) { if (settings.debug.value) Console.println(currentLevel.refsym); |