@@ -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, readAnnot, readWithin, NoSymbol )
516+ val (givenFlags, annotFns , privateWithin) = readModifiers(end, readAnnot, readWithin, NoSymbol )
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 _ =>
@@ -562,10 +561,10 @@ class TreeUnpickler(reader: TastyReader,
562561 * boundary symbol.
563562 */
564563 def readModifiers [WithinType , AnnotType ]
565- (end : Addr , readAnnot : Context => AnnotType , readWithin : Context => WithinType , defaultWithin : WithinType )
566- (implicit ctx : Context ): (FlagSet , List [AnnotType ], WithinType ) = {
564+ (end : Addr , readAnnot : Context => Symbol => AnnotType , readWithin : Context => WithinType , defaultWithin : WithinType )
565+ (implicit ctx : Context ): (FlagSet , List [Symbol => AnnotType ], WithinType ) = {
567566 var flags : FlagSet = EmptyFlags
568- var annots : List [AnnotType ] = Nil
567+ var annotFns : List [Symbol => AnnotType ] = Nil
569568 var privateWithin = defaultWithin
570569 while (currentAddr.index != end.index) {
571570 def addFlag (flag : FlagSet ) = {
@@ -617,29 +616,31 @@ class TreeUnpickler(reader: TastyReader,
617616 addFlag(Protected )
618617 privateWithin = readWithin(ctx)
619618 case ANNOTATION =>
620- annots = readAnnot(ctx) :: annots
619+ annotFns = readAnnot(ctx) :: annotFns
621620 case tag =>
622621 assert(false , s " illegal modifier tag $tag at $currentAddr, end = $end" )
623622 }
624623 }
625- (flags, annots .reverse, privateWithin)
624+ (flags, annotFns .reverse, privateWithin)
626625 }
627626
628627 private val readWithin : Context => Symbol =
629628 implicit ctx => readType().typeSymbol
630629
631- private val readAnnot : Context => Annotation = {
630+ private val readAnnot : Context => Symbol => Annotation = {
632631 implicit ctx =>
633632 readByte()
634633 val end = readEnd()
635634 val tp = readType()
636- val lazyAnnotTree = readLater(end, rdr => ctx => rdr.readTerm()(ctx))
637- if (tp.isRef(defn.BodyAnnot ))
638- LazyBodyAnnotation (implicit ctx => lazyAnnotTree.complete)
639- else
640- Annotation .deferredSymAndTree(
641- implicit ctx => tp.typeSymbol,
642- implicit ctx => lazyAnnotTree.complete)
635+ val lazyAnnotTree = readLaterWithOwner(end, rdr => ctx => rdr.readTerm()(ctx))
636+
637+ owner =>
638+ if (tp.isRef(defn.BodyAnnot ))
639+ LazyBodyAnnotation (implicit ctx => lazyAnnotTree(owner).complete)
640+ else
641+ Annotation .deferredSymAndTree(
642+ implicit ctx => tp.typeSymbol,
643+ implicit ctx => lazyAnnotTree(owner).complete)
643644 }
644645
645646 /** Create symbols for the definitions in the statement sequence between
@@ -1165,10 +1166,13 @@ class TreeUnpickler(reader: TastyReader,
11651166 setPos(start, CaseDef (pat, guard, rhs))
11661167 }
11671168
1168- def readLater [T <: AnyRef ](end : Addr , op : TreeReader => Context => T )(implicit ctx : Context ): Trees .Lazy [T ] = {
1169+ def readLater [T <: AnyRef ](end : Addr , op : TreeReader => Context => T )(implicit ctx : Context ): Trees .Lazy [T ] =
1170+ readLaterWithOwner(end, op)(ctx)(ctx.owner)
1171+
1172+ def readLaterWithOwner [T <: AnyRef ](end : Addr , op : TreeReader => Context => T )(implicit ctx : Context ): Symbol => Trees .Lazy [T ] = {
11691173 val localReader = fork
11701174 goto(end)
1171- new LazyReader (localReader, ctx. owner, ctx.mode, op)
1175+ owner => new LazyReader (localReader, owner, ctx.mode, op)
11721176 }
11731177
11741178 def readHole (end : Addr , isType : Boolean )(implicit ctx : Context ): Tree = {
@@ -1265,7 +1269,7 @@ class TreeUnpickler(reader: TastyReader,
12651269 def readMods (): untpd.Modifiers = {
12661270 val (flags, annots, privateWithin) =
12671271 readModifiers(end, readUntypedAnnot, readUntypedWithin, EmptyTypeName )
1268- untpd.Modifiers (flags, privateWithin, annots)
1272+ untpd.Modifiers (flags, privateWithin, annots.map(_( NoSymbol )) )
12691273 }
12701274
12711275 def readRhs (): untpd.Tree =
@@ -1384,8 +1388,8 @@ class TreeUnpickler(reader: TastyReader,
13841388 private val readUntypedWithin : Context => TypeName =
13851389 implicit ctx => readName().toTypeName
13861390
1387- private val readUntypedAnnot : Context => untpd.Tree =
1388- implicit ctx => readUntyped()
1391+ private val readUntypedAnnot : Context => Symbol => untpd.Tree =
1392+ implicit ctx => _ => readUntyped()
13891393
13901394// ------ Setting positions ------------------------------------------------
13911395
0 commit comments