Skip to content

Commit

Permalink
CheckUnused checks type param annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
som-snytt committed Aug 7, 2024
1 parent 8064536 commit 54344a1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
11 changes: 4 additions & 7 deletions compiler/src/dotty/tools/dotc/transform/CheckUnused.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
27 changes: 27 additions & 0 deletions tests/warn/i20536.scala
Original file line number Diff line number Diff line change
@@ -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
}
}

0 comments on commit 54344a1

Please sign in to comment.