Skip to content

Commit 5d41e78

Browse files
committed
Avoid retype checking of annotations
Previously the method `typedAheadAnnotation` is never called, which results in retyping of annotations when type checking a class. The problem is exhibited in the test tests/pos/t7426.scala: class foo(x: Any) extends annotation.StaticAnnotation @foo(new AnyRef { }) trait A Retype checking the annotation would resulting in entering the same symbol for the annonymous class twice. Previously, it does not cause problem, because we use an incorrect context for typeAhead checking the annotation, where the symbol is incorrectly entered in the class `A`. In the typer, a duplicate symbol is entered in the empty package, thus there is no conflict. Since we never check that a class member has a corresponding tree, the bug is thus hidden.
1 parent 44cb5fd commit 5d41e78

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -859,7 +859,7 @@ class Namer { typer: Typer =>
859859
if (cls eq sym)
860860
ctx.error("An annotation class cannot be annotated with iself", annotTree.sourcePos)
861861
else {
862-
val ann = Annotation.deferred(cls)(typedAnnotation(annotTree)(using annotCtx))(using annotCtx)
862+
val ann = Annotation.deferred(cls)(typedAheadAnnotation(annotTree)(using annotCtx))
863863
sym.addAnnotation(ann)
864864
}
865865
}

0 commit comments

Comments
 (0)