Skip to content

Commit 7864ebb

Browse files
authored
fix: emit deprecation warnings when a symbol is annotated by a deprecated annotation (#23906)
Closes #23905
2 parents 31299e2 + 8bd8f38 commit 7864ebb

File tree

4 files changed

+40
-0
lines changed

4 files changed

+40
-0
lines changed

compiler/src/dotty/tools/dotc/typer/CrossVersionChecks.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ class CrossVersionChecks extends MiniPhase:
3737
for annot <- sym.annotations if annot.symbol.isExperimental do
3838
Feature.checkExperimentalDef(annot.symbol, annot.tree)
3939

40+
private def checkDeprecatedAnnots(sym: Symbol)(using Context): Unit =
41+
if sym.exists then
42+
for annot <- sym.annotations if annot.symbol.isDeprecated do
43+
checkDeprecatedRef(annot.symbol, annot.tree.srcPos)
44+
4045
/** If @migration is present (indicating that the symbol has changed semantics between versions),
4146
* emit a warning.
4247
*/
@@ -102,18 +107,21 @@ class CrossVersionChecks extends MiniPhase:
102107
checkUnrollMemberDef(tree)
103108
checkDeprecatedOvers(tree)
104109
checkExperimentalAnnots(tree.symbol)
110+
checkDeprecatedAnnots(tree.symbol)
105111
tree
106112

107113
override def transformDefDef(tree: DefDef)(using Context): DefDef =
108114
checkUnrollMemberDef(tree)
109115
checkDeprecatedOvers(tree)
110116
checkExperimentalAnnots(tree.symbol)
117+
checkDeprecatedAnnots(tree.symbol)
111118
tree
112119

113120
override def transformTypeDef(tree: TypeDef)(using Context): TypeDef =
114121
// TODO do we need to check checkDeprecatedOvers(tree)?
115122
checkUnrollMemberDef(tree)
116123
checkExperimentalAnnots(tree.symbol)
124+
checkDeprecatedAnnots(tree.symbol)
117125
tree
118126

119127
override def transformTemplate(tree: tpd.Template)(using Context): tpd.Tree =

tests/warn/i23905.check

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
-- Deprecation Warning: tests/warn/i23905/Test_2.scala:3:0 -------------------------------------------------------------
3+
3 |@DeprecatedAnnotation // warn
4+
|^^^^^^^^^^^^^^^^^^^^^
5+
|class DeprecatedAnnotation is deprecated
6+
-- Deprecation Warning: tests/warn/i23905/Test_2.scala:6:0 -------------------------------------------------------------
7+
6 |@DeprecatedAnnotation // warn
8+
|^^^^^^^^^^^^^^^^^^^^^
9+
|class DeprecatedAnnotation is deprecated
10+
-- Deprecation Warning: tests/warn/i23905/Test_2.scala:9:0 -------------------------------------------------------------
11+
9 |@DeprecatedAnnotation // warn
12+
|^^^^^^^^^^^^^^^^^^^^^
13+
|class DeprecatedAnnotation is deprecated
14+
-- Deprecation Warning: tests/warn/i23905/Test_2.scala:12:0 ------------------------------------------------------------
15+
12 |@DeprecatedAnnotation // warn
16+
|^^^^^^^^^^^^^^^^^^^^^
17+
|class DeprecatedAnnotation is deprecated

tests/warn/i23905/Annot_1.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
@deprecated
2+
class DeprecatedAnnotation extends annotation.StaticAnnotation

tests/warn/i23905/Test_2.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//> using options -deprecation
2+
3+
@DeprecatedAnnotation // warn
4+
object Test1
5+
6+
@DeprecatedAnnotation // warn
7+
class Test2
8+
9+
@DeprecatedAnnotation // warn
10+
def Test3 = ???
11+
12+
@DeprecatedAnnotation // warn
13+
val Test4 = ???

0 commit comments

Comments
 (0)