@@ -28,6 +28,7 @@ import dotty.tools.dotc.core.Types.ConstantType
28
28
import dotty .tools .dotc .core .NameKinds .WildcardParamName
29
29
import dotty .tools .dotc .core .Types .TermRef
30
30
import dotty .tools .dotc .core .Types .NameFilter
31
+ import dotty .tools .dotc .core .Symbols .Symbol
31
32
32
33
33
34
@@ -103,6 +104,7 @@ class CheckUnused extends MiniPhase:
103
104
override def prepareForValDef (tree : tpd.ValDef )(using Context ): Context =
104
105
_key.unusedDataApply{ud =>
105
106
// do not register the ValDef generated for `object`
107
+ traverseAnnotations(tree.symbol)
106
108
if ! tree.symbol.is(Module ) then
107
109
ud.registerDef(tree)
108
110
ud.addIgnoredUsage(tree.symbol)
@@ -112,18 +114,21 @@ class CheckUnused extends MiniPhase:
112
114
_key.unusedDataApply{ ud =>
113
115
import ud .registerTrivial
114
116
tree.registerTrivial
117
+ traverseAnnotations(tree.symbol)
115
118
ud.registerDef(tree)
116
119
ud.addIgnoredUsage(tree.symbol)
117
120
}
118
121
119
122
override def prepareForTypeDef (tree : tpd.TypeDef )(using Context ): Context =
120
123
_key.unusedDataApply{ ud =>
121
124
if ! tree.symbol.is(Param ) then // Ignore type parameter (as Scala 2)
125
+ traverseAnnotations(tree.symbol)
122
126
ud.registerDef(tree)
123
127
ud.addIgnoredUsage(tree.symbol)
124
128
}
125
129
126
130
override def prepareForBind (tree : tpd.Bind )(using Context ): Context =
131
+ traverseAnnotations(tree.symbol)
127
132
_key.unusedDataApply(_.registerPatVar(tree))
128
133
129
134
override def prepareForTypeTree (tree : tpd.TypeTree )(using Context ): Context =
@@ -232,6 +237,10 @@ class CheckUnused extends MiniPhase:
232
237
case AnnotatedType (_, annot) => dt(_.registerUsed(annot.symbol, None ))
233
238
case _ => traverseChildren(tp)
234
239
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
+
235
244
/** Do the actual reporting given the result of the anaylsis */
236
245
private def reportUnused (res : UnusedData .UnusedResult )(using Context ): Unit =
237
246
import CheckUnused .WarnTypes
@@ -274,7 +283,6 @@ object CheckUnused:
274
283
private class UnusedData :
275
284
import dotty .tools .dotc .transform .CheckUnused .UnusedData .UnusedResult
276
285
import collection .mutable .{Set => MutSet , Map => MutMap , Stack => MutStack }
277
- import dotty .tools .dotc .core .Symbols .Symbol
278
286
import UnusedData .ScopeType
279
287
280
288
/** The current scope during the tree traversal */
@@ -324,11 +332,6 @@ object CheckUnused:
324
332
execInNewScope
325
333
popScope()
326
334
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
-
332
335
/**
333
336
* Register a found (used) symbol along with its name
334
337
*
@@ -363,8 +366,6 @@ object CheckUnused:
363
366
364
367
/** Register (or not) some `val` or `def` according to the context, scope and flags */
365
368
def registerDef (memDef : tpd.MemberDef )(using Context ): Unit =
366
- // register the annotations for usage
367
- registerUsedAnnotation(memDef.symbol)
368
369
if memDef.isValidMemberDef then
369
370
if memDef.isValidParam then
370
371
if memDef.symbol.isOneOf(GivenOrImplicit ) then
@@ -378,7 +379,6 @@ object CheckUnused:
378
379
379
380
/** Register pattern variable */
380
381
def registerPatVar (patvar : tpd.Bind )(using Context ): Unit =
381
- registerUsedAnnotation(patvar.symbol)
382
382
if ! patvar.symbol.isUnusedAnnot then
383
383
patVarsInScope += patvar
384
384
0 commit comments