@@ -16,6 +16,11 @@ import dotty.tools.dotc.typer.ImportInfo
16
16
import dotty .tools .dotc .util .Property
17
17
import dotty .tools .dotc .transform .CheckUnused .UnusedData .UnusedResult
18
18
import dotty .tools .dotc .core .Mode
19
+ import dotty .tools .dotc .core .Types .TypeTraverser
20
+ import dotty .tools .dotc .core .Types .Type
21
+ import dotty .tools .dotc .core .Types .AnnotatedType
22
+ import dotty .tools .dotc .core .Flags .flagsString
23
+ import dotty .tools .dotc .core .Flags
19
24
20
25
21
26
@@ -83,11 +88,19 @@ class CheckUnused extends Phase:
83
88
case t : tpd.Bind =>
84
89
unusedDataApply(_.registerPatVar(t))
85
90
traverseChildren(tree)(using newCtx)
91
+ case t@ tpd.TypeTree () =>
92
+ typeTraverser(unusedDataApply).traverse(t.tpe)
93
+ traverseChildren(tree)(using newCtx)
86
94
case _ =>
87
95
traverseChildren(tree)(using newCtx)
88
96
end traverse
89
97
end traverser
90
98
99
+ private def typeTraverser (dt : (UnusedData => Any ) => Unit )(using Context ) = new TypeTraverser :
100
+ override def traverse (tp : Type ): Unit = tp match
101
+ case AnnotatedType (_, annot) => dt(_.registerUsed(annot.symbol))
102
+ case _ => traverseChildren(tp)
103
+
91
104
private def reportUnused (res : UnusedData .UnusedResult )(using Context ): Unit =
92
105
import CheckUnused .WarnTypes
93
106
res.warnings.foreach { s =>
@@ -185,6 +198,8 @@ object CheckUnused:
185
198
if ! isConstructorOfSynth(sym) then
186
199
usedInScope.top += sym -> sym.isAccessibleAsIdent
187
200
usedDef += sym
201
+ if sym.isConstructor && sym.exists then
202
+ registerUsed(sym.owner) // constructor are "implicitly" imported with the class
188
203
189
204
/** Register a list of found (used) symbols */
190
205
def registerUsed (syms : Seq [Symbol ])(using Context ): Unit =
@@ -343,7 +358,7 @@ object CheckUnused:
343
358
val qualHasSymbol = qual.tpe.member(sym.name).symbol == sym
344
359
def selector = sels.find(sel => sel.name.toTermName == sym.name || sel.name.toTypeName == sym.name)
345
360
def wildcard = sels.find(sel => sel.isWildcard && ((sym.is(Given ) == sel.isGiven) || sym.is(Implicit )))
346
- if qualHasSymbol && ! isAccessible then
361
+ if qualHasSymbol && ! isAccessible && sym.exists then
347
362
selector.orElse(wildcard) // selector with name or wildcard (or given)
348
363
else
349
364
None
0 commit comments