Skip to content

Commit 068172b

Browse files
authored
Merge pull request #612 from scala/backport-lts-3.3-23906
Backport "fix: emit deprecation warnings when a symbol is annotated by a deprecated annotation" to 3.3 LTS
2 parents f878e95 + f8eb853 commit 068172b

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
*/
@@ -85,16 +90,19 @@ class CrossVersionChecks extends MiniPhase:
8590
override def transformValDef(tree: ValDef)(using Context): ValDef =
8691
checkDeprecatedOvers(tree)
8792
checkExperimentalAnnots(tree.symbol)
93+
checkDeprecatedAnnots(tree.symbol)
8894
tree
8995

9096
override def transformDefDef(tree: DefDef)(using Context): DefDef =
9197
checkDeprecatedOvers(tree)
9298
checkExperimentalAnnots(tree.symbol)
99+
checkDeprecatedAnnots(tree.symbol)
93100
tree
94101

95102
override def transformTypeDef(tree: TypeDef)(using Context): TypeDef =
96103
// TODO do we need to check checkDeprecatedOvers(tree)?
97104
checkExperimentalAnnots(tree.symbol)
105+
checkDeprecatedAnnots(tree.symbol)
98106
tree
99107

100108
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)