@@ -28,6 +28,7 @@ import dotty.tools.dotc.core.Types.ConstantType
2828import dotty .tools .dotc .core .NameKinds .WildcardParamName
2929import dotty .tools .dotc .core .Types .TermRef
3030import dotty .tools .dotc .core .Types .NameFilter
31+ import dotty .tools .dotc .core .Symbols .Symbol
3132
3233
3334
@@ -103,6 +104,7 @@ class CheckUnused extends MiniPhase:
103104 override def prepareForValDef (tree : tpd.ValDef )(using Context ): Context =
104105 _key.unusedDataApply{ud =>
105106 // do not register the ValDef generated for `object`
107+ traverseAnnotations(tree.symbol)
106108 if ! tree.symbol.is(Module ) then
107109 ud.registerDef(tree)
108110 ud.addIgnoredUsage(tree.symbol)
@@ -112,18 +114,21 @@ class CheckUnused extends MiniPhase:
112114 _key.unusedDataApply{ ud =>
113115 import ud .registerTrivial
114116 tree.registerTrivial
117+ traverseAnnotations(tree.symbol)
115118 ud.registerDef(tree)
116119 ud.addIgnoredUsage(tree.symbol)
117120 }
118121
119122 override def prepareForTypeDef (tree : tpd.TypeDef )(using Context ): Context =
120123 _key.unusedDataApply{ ud =>
121124 if ! tree.symbol.is(Param ) then // Ignore type parameter (as Scala 2)
125+ traverseAnnotations(tree.symbol)
122126 ud.registerDef(tree)
123127 ud.addIgnoredUsage(tree.symbol)
124128 }
125129
126130 override def prepareForBind (tree : tpd.Bind )(using Context ): Context =
131+ traverseAnnotations(tree.symbol)
127132 _key.unusedDataApply(_.registerPatVar(tree))
128133
129134 override def prepareForTypeTree (tree : tpd.TypeTree )(using Context ): Context =
@@ -232,6 +237,10 @@ class CheckUnused extends MiniPhase:
232237 case AnnotatedType (_, annot) => dt(_.registerUsed(annot.symbol, None ))
233238 case _ => traverseChildren(tp)
234239
240+ /** This traverse the annotations of the symbol */
241+ private def traverseAnnotations (sym : Symbol )(using Context ): Unit =
242+ sym.denot.annotations.foreach(annot => traverser.traverse(annot.tree))
243+
235244 /** Do the actual reporting given the result of the anaylsis */
236245 private def reportUnused (res : UnusedData .UnusedResult )(using Context ): Unit =
237246 import CheckUnused .WarnTypes
@@ -274,7 +283,6 @@ object CheckUnused:
274283 private class UnusedData :
275284 import dotty .tools .dotc .transform .CheckUnused .UnusedData .UnusedResult
276285 import collection .mutable .{Set => MutSet , Map => MutMap , Stack => MutStack }
277- import dotty .tools .dotc .core .Symbols .Symbol
278286 import UnusedData .ScopeType
279287
280288 /** The current scope during the tree traversal */
@@ -324,11 +332,6 @@ object CheckUnused:
324332 execInNewScope
325333 popScope()
326334
327- /** Register all annotations of this symbol's denotation */
328- def registerUsedAnnotation (sym : Symbol )(using Context ): Unit =
329- val annotSym = sym.denot.annotations.map(_.symbol)
330- annotSym.foreach(s => registerUsed(s, None ))
331-
332335 /**
333336 * Register a found (used) symbol along with its name
334337 *
@@ -363,8 +366,6 @@ object CheckUnused:
363366
364367 /** Register (or not) some `val` or `def` according to the context, scope and flags */
365368 def registerDef (memDef : tpd.MemberDef )(using Context ): Unit =
366- // register the annotations for usage
367- registerUsedAnnotation(memDef.symbol)
368369 if memDef.isValidMemberDef then
369370 if memDef.isValidParam then
370371 if memDef.symbol.isOneOf(GivenOrImplicit ) then
@@ -378,7 +379,6 @@ object CheckUnused:
378379
379380 /** Register pattern variable */
380381 def registerPatVar (patvar : tpd.Bind )(using Context ): Unit =
381- registerUsedAnnotation(patvar.symbol)
382382 if ! patvar.symbol.isUnusedAnnot then
383383 patVarsInScope += patvar
384384
0 commit comments