diff --git a/compiler/src/dotty/tools/dotc/transform/CheckUnused.scala b/compiler/src/dotty/tools/dotc/transform/CheckUnused.scala index d396d60c096a..337e41cf92de 100644 --- a/compiler/src/dotty/tools/dotc/transform/CheckUnused.scala +++ b/compiler/src/dotty/tools/dotc/transform/CheckUnused.scala @@ -135,25 +135,22 @@ class CheckUnused private (phaseMode: CheckUnused.PhaseMode, suffix: String, _ke } override def prepareForDefDef(tree: tpd.DefDef)(using Context): Context = - unusedDataApply{ ud => + unusedDataApply: ud => if !tree.symbol.is(Private) then tree.termParamss.flatten.foreach { p => ud.addIgnoredParam(p.symbol) } - import ud.registerTrivial - tree.registerTrivial + ud.registerTrivial(tree) traverseAnnotations(tree.symbol) ud.registerDef(tree) ud.addIgnoredUsage(tree.symbol) - } override def prepareForTypeDef(tree: tpd.TypeDef)(using Context): Context = - unusedDataApply{ ud => + unusedDataApply: ud => + traverseAnnotations(tree.symbol) if !tree.symbol.is(Param) then // Ignore type parameter (as Scala 2) - traverseAnnotations(tree.symbol) ud.registerDef(tree) ud.addIgnoredUsage(tree.symbol) - } override def prepareForBind(tree: tpd.Bind)(using Context): Context = traverseAnnotations(tree.symbol) diff --git a/tests/warn/i20536.scala b/tests/warn/i20536.scala new file mode 100644 index 000000000000..8f28c367e68d --- /dev/null +++ b/tests/warn/i20536.scala @@ -0,0 +1,27 @@ +//> using options -Wunused:all +object Anns { + final class S extends annotation.StaticAnnotation +} + +object Main { + locally { + import Anns.* + class C[@S A] + C().toString + } + locally { + import Anns.S as T + class C[@T A] + C().toString + } + locally { + import scala.specialized as T + class C[@T A] + C().toString + } + locally { + import scala.specialized as T // warn + class C[A] + C().toString + } +}