diff --git a/compiler/src/dotty/tools/dotc/typer/CrossVersionChecks.scala b/compiler/src/dotty/tools/dotc/typer/CrossVersionChecks.scala index 81a67d6a1df7..6f4eafa52e6d 100644 --- a/compiler/src/dotty/tools/dotc/typer/CrossVersionChecks.scala +++ b/compiler/src/dotty/tools/dotc/typer/CrossVersionChecks.scala @@ -37,6 +37,11 @@ class CrossVersionChecks extends MiniPhase: for annot <- sym.annotations if annot.symbol.isExperimental do Feature.checkExperimentalDef(annot.symbol, annot.tree) + private def checkDeprecatedAnnots(sym: Symbol)(using Context): Unit = + if sym.exists then + for annot <- sym.annotations if annot.symbol.isDeprecated do + checkDeprecatedRef(annot.symbol, annot.tree.srcPos) + /** If @migration is present (indicating that the symbol has changed semantics between versions), * emit a warning. */ @@ -102,18 +107,21 @@ class CrossVersionChecks extends MiniPhase: checkUnrollMemberDef(tree) checkDeprecatedOvers(tree) checkExperimentalAnnots(tree.symbol) + checkDeprecatedAnnots(tree.symbol) tree override def transformDefDef(tree: DefDef)(using Context): DefDef = checkUnrollMemberDef(tree) checkDeprecatedOvers(tree) checkExperimentalAnnots(tree.symbol) + checkDeprecatedAnnots(tree.symbol) tree override def transformTypeDef(tree: TypeDef)(using Context): TypeDef = // TODO do we need to check checkDeprecatedOvers(tree)? checkUnrollMemberDef(tree) checkExperimentalAnnots(tree.symbol) + checkDeprecatedAnnots(tree.symbol) tree override def transformTemplate(tree: tpd.Template)(using Context): tpd.Tree = diff --git a/tests/warn/i23905.check b/tests/warn/i23905.check new file mode 100644 index 000000000000..9ca2ca0fb200 --- /dev/null +++ b/tests/warn/i23905.check @@ -0,0 +1,17 @@ + +-- Deprecation Warning: tests/warn/i23905/Test_2.scala:3:0 ------------------------------------------------------------- +3 |@DeprecatedAnnotation // warn + |^^^^^^^^^^^^^^^^^^^^^ + |class DeprecatedAnnotation is deprecated +-- Deprecation Warning: tests/warn/i23905/Test_2.scala:6:0 ------------------------------------------------------------- +6 |@DeprecatedAnnotation // warn + |^^^^^^^^^^^^^^^^^^^^^ + |class DeprecatedAnnotation is deprecated +-- Deprecation Warning: tests/warn/i23905/Test_2.scala:9:0 ------------------------------------------------------------- +9 |@DeprecatedAnnotation // warn + |^^^^^^^^^^^^^^^^^^^^^ + |class DeprecatedAnnotation is deprecated +-- Deprecation Warning: tests/warn/i23905/Test_2.scala:12:0 ------------------------------------------------------------ +12 |@DeprecatedAnnotation // warn + |^^^^^^^^^^^^^^^^^^^^^ + |class DeprecatedAnnotation is deprecated diff --git a/tests/warn/i23905/Annot_1.scala b/tests/warn/i23905/Annot_1.scala new file mode 100644 index 000000000000..e13664c67ebd --- /dev/null +++ b/tests/warn/i23905/Annot_1.scala @@ -0,0 +1,2 @@ +@deprecated +class DeprecatedAnnotation extends annotation.StaticAnnotation diff --git a/tests/warn/i23905/Test_2.scala b/tests/warn/i23905/Test_2.scala new file mode 100644 index 000000000000..248e923a5d83 --- /dev/null +++ b/tests/warn/i23905/Test_2.scala @@ -0,0 +1,13 @@ +//> using options -deprecation + +@DeprecatedAnnotation // warn +object Test1 + +@DeprecatedAnnotation // warn +class Test2 + +@DeprecatedAnnotation // warn +def Test3 = ??? + +@DeprecatedAnnotation // warn +val Test4 = ???