@@ -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
@@ -80,7 +81,7 @@ class CheckUnused extends MiniPhase:
80
81
ctx
81
82
82
83
override def prepareForIdent (tree : tpd.Ident )(using Context ): Context =
83
- if tree.symbol.exists then
84
+ if tree.symbol.exists then
84
85
unusedDataApply(_.registerUsed(tree.symbol, Some (tree.name)))
85
86
else if tree.hasType then
86
87
unusedDataApply(_.registerUsed(tree.tpe.classSymbol, Some (tree.name)))
@@ -102,6 +103,7 @@ class CheckUnused extends MiniPhase:
102
103
override def prepareForValDef (tree : tpd.ValDef )(using Context ): Context =
103
104
unusedDataApply{ud =>
104
105
// do not register the ValDef generated for `object`
106
+ traverseAnnotations(tree.symbol)
105
107
if ! tree.symbol.is(Module ) then
106
108
ud.registerDef(tree)
107
109
ud.addIgnoredUsage(tree.symbol)
@@ -111,18 +113,21 @@ class CheckUnused extends MiniPhase:
111
113
unusedDataApply{ ud =>
112
114
import ud .registerTrivial
113
115
tree.registerTrivial
116
+ traverseAnnotations(tree.symbol)
114
117
ud.registerDef(tree)
115
118
ud.addIgnoredUsage(tree.symbol)
116
119
}
117
120
118
121
override def prepareForTypeDef (tree : tpd.TypeDef )(using Context ): Context =
119
122
unusedDataApply{ ud =>
120
123
if ! tree.symbol.is(Param ) then // Ignore type parameter (as Scala 2)
124
+ traverseAnnotations(tree.symbol)
121
125
ud.registerDef(tree)
122
126
ud.addIgnoredUsage(tree.symbol)
123
127
}
124
128
125
129
override def prepareForBind (tree : tpd.Bind )(using Context ): Context =
130
+ traverseAnnotations(tree.symbol)
126
131
unusedDataApply(_.registerPatVar(tree))
127
132
128
133
override def prepareForTypeTree (tree : tpd.TypeTree )(using Context ): Context =
@@ -237,6 +242,10 @@ class CheckUnused extends MiniPhase:
237
242
case _ =>
238
243
traverseChildren(tp)
239
244
245
+ /** This traverse the annotations of the symbol */
246
+ private def traverseAnnotations (sym : Symbol )(using Context ): Unit =
247
+ sym.denot.annotations.foreach(annot => traverser.traverse(annot.tree))
248
+
240
249
/** Do the actual reporting given the result of the anaylsis */
241
250
private def reportUnused (res : UnusedData .UnusedResult )(using Context ): Unit =
242
251
import CheckUnused .WarnTypes
@@ -279,7 +288,6 @@ object CheckUnused:
279
288
private class UnusedData :
280
289
import dotty .tools .dotc .transform .CheckUnused .UnusedData .UnusedResult
281
290
import collection .mutable .{Set => MutSet , Map => MutMap , Stack => MutStack }
282
- import dotty .tools .dotc .core .Symbols .Symbol
283
291
import UnusedData .ScopeType
284
292
285
293
/** The current scope during the tree traversal */
@@ -329,11 +337,6 @@ object CheckUnused:
329
337
execInNewScope
330
338
popScope()
331
339
332
- /** Register all annotations of this symbol's denotation */
333
- def registerUsedAnnotation (sym : Symbol )(using Context ): Unit =
334
- val annotSym = sym.denot.annotations.map(_.symbol)
335
- annotSym.foreach(s => registerUsed(s, None ))
336
-
337
340
/**
338
341
* Register a found (used) symbol along with its name
339
342
*
@@ -368,8 +371,6 @@ object CheckUnused:
368
371
369
372
/** Register (or not) some `val` or `def` according to the context, scope and flags */
370
373
def registerDef (memDef : tpd.MemberDef )(using Context ): Unit =
371
- // register the annotations for usage
372
- registerUsedAnnotation(memDef.symbol)
373
374
if memDef.isValidMemberDef then
374
375
if memDef.isValidParam then
375
376
if memDef.symbol.isOneOf(GivenOrImplicit ) then
@@ -383,7 +384,6 @@ object CheckUnused:
383
384
384
385
/** Register pattern variable */
385
386
def registerPatVar (patvar : tpd.Bind )(using Context ): Unit =
386
- registerUsedAnnotation(patvar.symbol)
387
387
if ! patvar.symbol.isUnusedAnnot then
388
388
patVarsInScope += patvar
389
389
0 commit comments