Skip to content

Commit 08ba889

Browse files
committed
Mark single-use field MUTABLE for nullification (Fixes scala/bug#11781)
1 parent 6194a88 commit 08ba889

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,8 +409,10 @@ abstract class Mixin extends InfoTransform with ast.TreeDSL with AccessorSynthes
409409
deriveDefDef(dd) {
410410
case blk@Block(stats, expr) =>
411411
assert(dd.symbol.originalOwner.isClass, dd.symbol)
412-
def nullify(sym: Symbol) =
412+
def nullify(sym: Symbol) = {
413+
sym.accessedOrSelf.setFlag(MUTABLE)
413414
Select(gen.mkAttributedThis(sym.enclClass), sym.accessedOrSelf) === NULL
415+
}
414416
val stats1 = stats ::: fieldsToNull.map(nullify)
415417
treeCopy.Block(blk, stats1, expr)
416418
case tree =>

test/junit/scala/tools/nsc/backend/jvm/BytecodeTest.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,4 +303,13 @@ class BytecodeTest extends BytecodeTesting {
303303
}
304304
assertEquals(List("$outer", "x$1", "y$1"), assignedInConstr.sorted)
305305
}
306+
307+
@Test
308+
def t11718(): Unit = {
309+
val code = "class A11718; class B11718 { private val a = new A; lazy val b = a }"
310+
val cs = compileClasses(code)
311+
val B = cs.find(_.name == "B11718").get
312+
val a = B.fields.asScala.find(_.name == "a").get
313+
assertEquals(0, a.access & Opcodes.ACC_FINAL)
314+
}
306315
}

0 commit comments

Comments
 (0)