Skip to content

Commit 889d788

Browse files
committed
Mangle string for getDeclaredField on LazyVals
1 parent 4353ae4 commit 889d788

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

compiler/src/dotty/tools/dotc/transform/LazyVals.scala

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -454,9 +454,7 @@ class LazyVals extends MiniPhase with IdentityDenotTransformer {
454454
var offsetSymbol: TermSymbol | Null = null
455455

456456
def offsetName(id: Int) = s"${StdNames.nme.LAZY_FIELD_OFFSET}${if (x.symbol.owner.is(Module)) "_m_" else ""}$id".toTermName
457-
458457
val containerName = LazyLocalName.fresh(x.name.asTermName)
459-
val containerNameEscaped = containerName.toString.replace(" ", "$u0020") // escape spaces in names
460458
val containerSymbol = newSymbol(claz, containerName, containerFlags, defn.ObjectType).enteredAfter(this)
461459
containerSymbol.addAnnotation(Annotation(defn.VolatileAnnot)) // private @volatile var _x: AnyRef
462460
containerSymbol.addAnnotations(x.symbol.annotations) // pass annotations from original definition
@@ -475,13 +473,13 @@ class LazyVals extends MiniPhase with IdentityDenotTransformer {
475473
case Some(info) =>
476474
offsetSymbol = newSymbol(claz, offsetName(info.defs.size), Synthetic, defn.LongType).enteredAfter(this)
477475
offsetSymbol.nn.addAnnotation(Annotation(defn.ScalaStaticAnnot))
478-
val fieldTree = thizClass.select(lazyNme.RLazyVals.getDeclaredField).appliedTo(Literal(Constant(containerNameEscaped)))
476+
val fieldTree = thizClass.select(lazyNme.RLazyVals.getDeclaredField).appliedTo(Literal(Constant(containerName.mangledString)))
479477
val offsetTree = ValDef(offsetSymbol.nn, getOffset.appliedTo(fieldTree))
480478
info.defs = offsetTree :: info.defs
481479
case None =>
482480
offsetSymbol = newSymbol(claz, offsetName(0), Synthetic, defn.LongType).enteredAfter(this)
483481
offsetSymbol.nn.addAnnotation(Annotation(defn.ScalaStaticAnnot))
484-
val fieldTree = thizClass.select(lazyNme.RLazyVals.getDeclaredField).appliedTo(Literal(Constant(containerNameEscaped)))
482+
val fieldTree = thizClass.select(lazyNme.RLazyVals.getDeclaredField).appliedTo(Literal(Constant(containerName.mangledString)))
485483
val offsetTree = ValDef(offsetSymbol.nn, getOffset.appliedTo(fieldTree))
486484
appendOffsetDefs += (claz -> new OffsetInfo(List(offsetTree)))
487485

0 commit comments

Comments
 (0)