Skip to content

Commit 719391d

Browse files
committed
Fix wrong owner when reading annotations.
This was the enclosing class instead of the method containing the annotation. Fixing this is surprisingly hard.
1 parent af61f0f commit 719391d

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

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

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ class TreeUnpickler(reader: TastyReader,
513513
val rhsStart = currentAddr
514514
val rhsIsEmpty = nothingButMods(end)
515515
if (!rhsIsEmpty) skipTree()
516-
val (givenFlags, annotFns, privateWithin) = readModifiers(end)
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) =
@@ -561,10 +561,10 @@ class TreeUnpickler(reader: TastyReader,
561561
* boundary symbol.
562562
*/
563563
def readModifiers[WithinType, AnnotType]
564-
(end: Addr, readAnnot: Context => AnnotType, readWithin: Context => WithinType, defaultWithin: WithinType)
565-
(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) = {
566566
var flags: FlagSet = EmptyFlags
567-
var annotFns: List[Symbol => Annotation] = Nil
567+
var annotFns: List[Symbol => AnnotType] = Nil
568568
var privateWithin = defaultWithin
569569
while (currentAddr.index != end.index) {
570570
def addFlag(flag: FlagSet) = {
@@ -633,12 +633,14 @@ class TreeUnpickler(reader: TastyReader,
633633
val end = readEnd()
634634
val tp = readType()
635635
val lazyAnnotTree = readLaterWithOwner(end, rdr => ctx => rdr.readTerm()(ctx))
636-
if (tp.isRef(defn.BodyAnnot))
637-
LazyBodyAnnotation(implicit ctx => lazyAnnotTree(owner).complete)
638-
else
639-
Annotation.deferredSymAndTree(
640-
implicit ctx => tp.typeSymbol,
641-
implicit ctx => lazyAnnotTree(owner).complete)
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)
642644
}
643645

644646
/** Create symbols for the definitions in the statement sequence between
@@ -1267,7 +1269,7 @@ class TreeUnpickler(reader: TastyReader,
12671269
def readMods(): untpd.Modifiers = {
12681270
val (flags, annots, privateWithin) =
12691271
readModifiers(end, readUntypedAnnot, readUntypedWithin, EmptyTypeName)
1270-
untpd.Modifiers(flags, privateWithin, annots)
1272+
untpd.Modifiers(flags, privateWithin, annots.map(_(NoSymbol)))
12711273
}
12721274

12731275
def readRhs(): untpd.Tree =
@@ -1386,8 +1388,8 @@ class TreeUnpickler(reader: TastyReader,
13861388
private val readUntypedWithin: Context => TypeName =
13871389
implicit ctx => readName().toTypeName
13881390

1389-
private val readUntypedAnnot: Context => untpd.Tree =
1390-
implicit ctx => readUntyped()
1391+
private val readUntypedAnnot: Context => Symbol => untpd.Tree =
1392+
implicit ctx => _ => readUntyped()
13911393

13921394
// ------ Setting positions ------------------------------------------------
13931395

0 commit comments

Comments
 (0)