@@ -2779,7 +2779,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
27792779 def isInner (owner : Symbol ) = owner == sym || sym.is(Param ) && owner == sym.owner
27802780 val outer = ctx.outersIterator.dropWhile(c => isInner(c.owner)).next()
27812781 def local : FreshContext = outer.fresh.setOwner(newLocalDummy(sym.owner))
2782- sym.owner.infoOrCompleter match
2782+ val ctx0 = sym.owner.infoOrCompleter match
27832783 case completer : Namer # Completer
27842784 if sym.is(Param ) && completer.completerTypeParams(sym).nonEmpty =>
27852785 // Create a new local context with a dummy owner and a scope containing the
@@ -2788,6 +2788,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
27882788 local.setScope(newScopeWith(completer.completerTypeParams(sym)* ))
27892789 case _ =>
27902790 if outer.owner.isClass then local else outer
2791+ ctx0.addMode(Mode .InAnnotation )
27912792
27922793 def completeAnnotations (mdef : untpd.MemberDef , sym : Symbol )(using Context ): Unit = {
27932794 // necessary to force annotation trees to be computed.
@@ -2802,7 +2803,8 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
28022803 }
28032804
28042805 def typedAnnotation (annot : untpd.Tree )(using Context ): Tree =
2805- checkAnnotClass(checkAnnotArgs(typed(annot)))
2806+ val typedAnnot = withMode(Mode .InAnnotation )(typed(annot))
2807+ checkAnnotClass(checkAnnotArgs(typedAnnot))
28062808
28072809 def registerNowarn (tree : Tree , mdef : untpd.Tree )(using Context ): Unit =
28082810 val annot = Annotations .Annotation (tree)
@@ -3335,7 +3337,8 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
33353337 end typedPackageDef
33363338
33373339 def typedAnnotated (tree : untpd.Annotated , pt : Type )(using Context ): Tree = {
3338- val annot1 = checkAnnotClass(typedExpr(tree.annot))
3340+ val annot0 = withMode(Mode .InAnnotation )(typedExpr(tree.annot))
3341+ val annot1 = checkAnnotClass(annot0)
33393342 val annotCls = Annotations .annotClass(annot1)
33403343 if annotCls == defn.NowarnAnnot then
33413344 registerNowarn(annot1, tree)
0 commit comments