Skip to content

Commit cf845ab

Browse files
committed
don't suppress field for unit-typed vals
it affects the memory model -- even a write of unit to a field is relevant...
1 parent 675f937 commit cf845ab

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

src/compiler/scala/tools/nsc/transform/Fields.scala

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,8 @@ abstract class Fields extends InfoTransform with ast.TreeDSL with TypingTransfor
137137
// not stored, no side-effect
138138
val pureConstant = tp.isInstanceOf[ConstantType]
139139

140-
val stored = !(pureConstant || isUnitType(tp))
140+
val stored = !(pureConstant) // || isUnitType(tp))
141141

142-
// - setter (for var) or getter (for val) that isn't stored
143-
// (pureConstant already shortcircuits this, but it may still be a unit-typed val)
144-
def deriveStoredAccessor(stat: Tree)(deriveUnitDef: Tree => Tree) =
145-
if (!stored) deriveUnitDef(stat)
146-
else stat
147142

148143
// println(s"fieldMemoizationIn $sym $site = $tp")
149144
def assignSym: Symbol =
@@ -448,7 +443,11 @@ abstract class Fields extends InfoTransform with ast.TreeDSL with TypingTransfor
448443

449444
def dropRhs = deriveDefDef(stat)(_ => EmptyTree)
450445
implicit val fieldMemoization = fieldMemoizationIn(statSym, clazz)
451-
def deriveStoredAccessor(tree: Tree) = fieldMemoization.deriveStoredAccessor(tree)(deriveUnitDef)
446+
447+
def deriveStoredAccessor(stat: Tree) = stat
448+
// if we decide to have non-stored fields with initialization effects:
449+
// if (!fieldMemoization.stored) deriveUnitDef(stat)
450+
// else stat
452451

453452
if (clazz.isTrait)
454453
if (fieldMemoization.pureConstant) stat :: Nil
@@ -464,7 +463,7 @@ abstract class Fields extends InfoTransform with ast.TreeDSL with TypingTransfor
464463
// drop the val for (a) constant (pure & not-stored) and (b) not-stored (but still effectful) fields
465464
if (fieldMemoization.pureConstant) Nil // (a)
466465
else if (fieldMemoization.stored) dropRhs :: init(rhs)
467-
else init(rhs) // (b)
466+
else init(rhs) // (b) -- not used currently
468467

469468
case tree => List (
470469
if (exprOwner != currentOwner && tree.isTerm) atOwner(exprOwner)(super.transform(tree))

0 commit comments

Comments
 (0)