Skip to content

Commit

Permalink
Backport "CheckUnused checks type param annotations" to LTS (#22091)
Browse files Browse the repository at this point in the history
Backports #20549 to the 3.3.5.

PR submitted by the release tooling.
[skip ci]
  • Loading branch information
WojciechMazur authored Dec 3, 2024
2 parents c3868fa + 66626bc commit 5b7fbdd
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 5b7fbdd

Please sign in to comment.