@@ -513,7 +513,7 @@ class TreeUnpickler(reader: TastyReader,
513513 val rhsStart = currentAddr
514514 val rhsIsEmpty = nothingButMods(end)
515515 if (! rhsIsEmpty) skipTree()
516- val (givenFlags, annots , privateWithin) = readModifiers(end)
516+ val (givenFlags, annotFns , privateWithin) = readModifiers(end)
517517 pickling.println(i " creating symbol $name at $start with flags $givenFlags" )
518518 val flags = normalizeFlags(tag, givenFlags, name, isAbsType, rhsIsEmpty)
519519 def adjustIfModule (completer : LazyType ) =
@@ -532,13 +532,12 @@ class TreeUnpickler(reader: TastyReader,
532532 rootd.symbol
533533 case _ =>
534534 val completer = adjustIfModule(new Completer (ctx.owner, subReader(start, end)))
535-
536535 if (isClass)
537536 ctx.newClassSymbol(ctx.owner, name.asTypeName, flags, completer, privateWithin, coord)
538537 else
539538 ctx.newSymbol(ctx.owner, name, flags, completer, privateWithin, coord)
540539 }
541- sym.annotations = annots
540+ sym.annotations = annotFns.map(_(sym))
542541 ctx.owner match {
543542 case cls : ClassSymbol => cls.enter(sym)
544543 case _ =>
@@ -561,9 +560,9 @@ class TreeUnpickler(reader: TastyReader,
561560 /** Read modifier list into triplet of flags, annotations and a privateWithin
562561 * boundary symbol.
563562 */
564- def readModifiers (end : Addr )(implicit ctx : Context ): (FlagSet , List [Annotation ], Symbol ) = {
563+ def readModifiers (end : Addr )(implicit ctx : Context ): (FlagSet , List [Symbol => Annotation ], Symbol ) = {
565564 var flags : FlagSet = EmptyFlags
566- var annots : List [Annotation ] = Nil
565+ var annotFns : List [Symbol => Annotation ] = Nil
567566 var privateWithin : Symbol = NoSymbol
568567 while (currentAddr.index != end.index) {
569568 def addFlag (flag : FlagSet ) = {
@@ -615,23 +614,25 @@ class TreeUnpickler(reader: TastyReader,
615614 addFlag(Protected )
616615 privateWithin = readType().typeSymbol
617616 case ANNOTATION =>
618- annots = readAnnot(ctx) :: annots
617+ annotFns = readAnnot(ctx) :: annotFns
619618 case tag =>
620619 assert(false , s " illegal modifier tag $tag at $currentAddr, end = $end" )
621620 }
622621 }
623- (flags, annots .reverse, privateWithin)
622+ (flags, annotFns .reverse, privateWithin)
624623 }
625624
626- private val readAnnot : Context => Annotation = {
625+ private val readAnnot : Context => Symbol => Annotation = {
627626 implicit ctx =>
628627 readByte()
629628 val end = readEnd()
630629 val tp = readType()
631- val lazyAnnotTree = readLater(end, rdr => ctx => rdr.readTerm()(ctx))
632- Annotation .deferredSymAndTree(
633- implicit ctx => tp.typeSymbol,
634- implicit ctx => lazyAnnotTree.complete)
630+ val lazyAnnotTree = readLaterWithOwner(end, rdr => ctx => rdr.readTerm()(ctx))
631+
632+ owner =>
633+ Annotation .deferredSymAndTree(
634+ implicit ctx => tp.typeSymbol,
635+ implicit ctx => lazyAnnotTree(owner).complete)
635636 }
636637
637638 /** Create symbols for the definitions in the statement sequence between
@@ -1154,10 +1155,13 @@ class TreeUnpickler(reader: TastyReader,
11541155 setPos(start, CaseDef (pat, guard, rhs))
11551156 }
11561157
1157- def readLater [T <: AnyRef ](end : Addr , op : TreeReader => Context => T )(implicit ctx : Context ): Trees .Lazy [T ] = {
1158+ def readLater [T <: AnyRef ](end : Addr , op : TreeReader => Context => T )(implicit ctx : Context ): Trees .Lazy [T ] =
1159+ readLaterWithOwner(end, op)(ctx)(ctx.owner)
1160+
1161+ def readLaterWithOwner [T <: AnyRef ](end : Addr , op : TreeReader => Context => T )(implicit ctx : Context ): Symbol => Trees .Lazy [T ] = {
11581162 val localReader = fork
11591163 goto(end)
1160- new LazyReader (localReader, ctx. owner, ctx.mode, op)
1164+ owner => new LazyReader (localReader, owner, ctx.mode, op)
11611165 }
11621166
11631167 def readHole (end : Addr , isType : Boolean )(implicit ctx : Context ): Tree = {
0 commit comments