Skip to content

Commit 54344a1

Browse files
committed
CheckUnused checks type param annotations
1 parent 8064536 commit 54344a1

File tree

2 files changed

+31
-7
lines changed

2 files changed

+31
-7
lines changed

compiler/src/dotty/tools/dotc/transform/CheckUnused.scala

+4-7
Original file line numberDiff line numberDiff line change
@@ -135,25 +135,22 @@ class CheckUnused private (phaseMode: CheckUnused.PhaseMode, suffix: String, _ke
135135
}
136136

137137
override def prepareForDefDef(tree: tpd.DefDef)(using Context): Context =
138-
unusedDataApply{ ud =>
138+
unusedDataApply: ud =>
139139
if !tree.symbol.is(Private) then
140140
tree.termParamss.flatten.foreach { p =>
141141
ud.addIgnoredParam(p.symbol)
142142
}
143-
import ud.registerTrivial
144-
tree.registerTrivial
143+
ud.registerTrivial(tree)
145144
traverseAnnotations(tree.symbol)
146145
ud.registerDef(tree)
147146
ud.addIgnoredUsage(tree.symbol)
148-
}
149147

150148
override def prepareForTypeDef(tree: tpd.TypeDef)(using Context): Context =
151-
unusedDataApply{ ud =>
149+
unusedDataApply: ud =>
150+
traverseAnnotations(tree.symbol)
152151
if !tree.symbol.is(Param) then // Ignore type parameter (as Scala 2)
153-
traverseAnnotations(tree.symbol)
154152
ud.registerDef(tree)
155153
ud.addIgnoredUsage(tree.symbol)
156-
}
157154

158155
override def prepareForBind(tree: tpd.Bind)(using Context): Context =
159156
traverseAnnotations(tree.symbol)

tests/warn/i20536.scala

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//> using options -Wunused:all
2+
object Anns {
3+
final class S extends annotation.StaticAnnotation
4+
}
5+
6+
object Main {
7+
locally {
8+
import Anns.*
9+
class C[@S A]
10+
C().toString
11+
}
12+
locally {
13+
import Anns.S as T
14+
class C[@T A]
15+
C().toString
16+
}
17+
locally {
18+
import scala.specialized as T
19+
class C[@T A]
20+
C().toString
21+
}
22+
locally {
23+
import scala.specialized as T // warn
24+
class C[A]
25+
C().toString
26+
}
27+
}

0 commit comments

Comments
 (0)