Skip to content

Commit fb0d6b7

Browse files
committed
TreeUnpickler: do not capture Context in Annotation symbol
1 parent 9f823cf commit fb0d6b7

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

compiler/src/dotty/tools/dotc/core/Annotations.scala

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,17 @@ object Annotations {
117117
}
118118

119119
/** Create an annotation where the symbol and the tree are computed lazily. */
120-
def deferredSymAndTree(sym: => Symbol, treeFn: Context => Tree)(implicit ctx: Context): Annotation =
120+
def deferredSymAndTree(symf: Context => Symbol, treeFn: Context => Tree)(implicit ctx: Context): Annotation =
121121
new LazyAnnotation {
122-
lazy val symf = sym
123-
124-
override def symbol(implicit ctx: Context): Symbol = symf
122+
private[this] var mySym: Symbol = _
123+
124+
override def symbol(implicit ctx: Context): Symbol = {
125+
if (mySym == null) {
126+
mySym = symf(ctx)
127+
assert(mySym != null)
128+
}
129+
mySym
130+
}
125131
def complete(implicit ctx: Context) = treeFn(ctx)
126132
}
127133

compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,9 @@ class TreeUnpickler(reader: TastyReader, tastyName: TastyName.Table, posUnpickle
554554
val end = readEnd()
555555
val tp = readType()
556556
val lazyAnnotTree = readLater(end, rdr => ctx => rdr.readTerm()(ctx))
557-
annots += Annotation.deferredSymAndTree(tp.typeSymbol, implicit ctx => lazyAnnotTree.complete)
557+
annots += Annotation.deferredSymAndTree(
558+
implicit ctx => tp.typeSymbol,
559+
implicit ctx => lazyAnnotTree.complete)
558560
case tag =>
559561
assert(false, s"illegal modifier tag $tag at $currentAddr, end = $end")
560562
}

0 commit comments

Comments
 (0)