Skip to content

Commit e88a6a5

Browse files
authored
Merge pull request #4662 from dotty-staging/fix/typedAheadAnnotation
Avoid typing annotations twice
2 parents f2f190d + 924a63b commit e88a6a5

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

compiler/src/dotty/tools/dotc/typer/Namer.scala

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -745,10 +745,11 @@ class Namer { typer: Typer =>
745745
while (c.owner != target) c = c.outer
746746
c
747747
}
748+
748749
for (annotTree <- untpd.modsDeco(stat).mods.annotations) {
749-
val cls = typedAheadAnnotation(annotTree)(annotCtx)
750+
val cls = typedAheadAnnotationClass(annotTree)(annotCtx)
750751
if (sym.unforcedAnnotation(cls).isEmpty) {
751-
val ann = Annotation.deferred(cls, implicit ctx => typedAnnotation(annotTree))
752+
val ann = Annotation.deferred(cls, implicit ctx => typedAheadAnnotation(annotTree))
752753
sym.addAnnotation(ann)
753754
if (cls == defn.InlineAnnot && sym.is(Method, butNot = Accessor))
754755
sym.setFlag(Inline)
@@ -1012,10 +1013,13 @@ class Namer { typer: Typer =>
10121013
def typedAheadExpr(tree: Tree, pt: Type = WildcardType)(implicit ctx: Context): tpd.Tree =
10131014
typedAheadImpl(tree, typer.typed(_, pt)(ctx retractMode Mode.PatternOrTypeBits))
10141015

1015-
def typedAheadAnnotation(tree: Tree)(implicit ctx: Context): Symbol = tree match {
1016-
case Apply(fn, _) => typedAheadAnnotation(fn)
1017-
case TypeApply(fn, _) => typedAheadAnnotation(fn)
1018-
case Select(qual, nme.CONSTRUCTOR) => typedAheadAnnotation(qual)
1016+
def typedAheadAnnotation(tree: Tree)(implicit ctx: Context): tpd.Tree =
1017+
typedAheadExpr(tree, defn.AnnotationType)
1018+
1019+
def typedAheadAnnotationClass(tree: Tree)(implicit ctx: Context): Symbol = tree match {
1020+
case Apply(fn, _) => typedAheadAnnotationClass(fn)
1021+
case TypeApply(fn, _) => typedAheadAnnotationClass(fn)
1022+
case Select(qual, nme.CONSTRUCTOR) => typedAheadAnnotationClass(qual)
10191023
case New(tpt) => typedAheadType(tpt).tpe.classSymbol
10201024
}
10211025

0 commit comments

Comments
 (0)