Skip to content

Commit 040e385

Browse files
committed
Add support for @deprecatedName
1 parent 55c2002 commit 040e385

File tree

4 files changed

+23
-0
lines changed

4 files changed

+23
-0
lines changed

compiler/src/dotty/tools/dotc/core/Definitions.scala

+1
Original file line numberDiff line numberDiff line change
@@ -1006,6 +1006,7 @@ class Definitions {
10061006
@tu lazy val ProvisionalSuperClassAnnot: ClassSymbol = requiredClass("scala.annotation.internal.ProvisionalSuperClass")
10071007
@tu lazy val DeprecatedAnnot: ClassSymbol = requiredClass("scala.deprecated")
10081008
@tu lazy val DeprecatedOverridingAnnot: ClassSymbol = requiredClass("scala.deprecatedOverriding")
1009+
@tu lazy val DeprecatedNameAnnot: ClassSymbol = requiredClass("scala.deprecatedName")
10091010
@tu lazy val ImplicitAmbiguousAnnot: ClassSymbol = requiredClass("scala.annotation.implicitAmbiguous")
10101011
@tu lazy val ImplicitNotFoundAnnot: ClassSymbol = requiredClass("scala.annotation.implicitNotFound")
10111012
@tu lazy val InlineParamAnnot: ClassSymbol = requiredClass("scala.annotation.internal.InlineParam")

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

+12
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import core.*
55
import Names.*
66
import dotty.tools.dotc.transform.MegaPhase.*
77
import ast.untpd
8+
import ast.tpd
89
import Flags.*
910
import Types.*
1011
import Constants.Constant
@@ -174,6 +175,17 @@ class FirstTransform extends MiniPhase with InfoTransformer { thisPhase =>
174175
override def transformTypeApply(tree: TypeApply)(using Context): Tree =
175176
constToLiteral(tree)
176177

178+
override def prepareForApply(tree: tpd.Apply)(using Context): Context =
179+
val paramSymss = tree.symbol.paramSymss.flatten
180+
for namedArg <- tree.args.filterConserve(isNamedArg).asInstanceOf[List[NamedArg]]
181+
name = namedArg.name
182+
// We will have at most one parameter (we have 0 if the parameter name changed with a refined type)
183+
sym <- paramSymss.filter(_.name == name)
184+
annot <- sym.getAnnotation(defn.DeprecatedNameAnnot)
185+
do
186+
report.deprecationWarning(em"naming parameter $name is deprecated", namedArg.srcPos)
187+
ctx
188+
177189
override def transformApply(tree: Apply)(using Context): Tree =
178190
constToLiteral(foldCondition(tree))
179191

tests/warn/i19077.check

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
-- Deprecation Warning: tests/warn/i19077.scala:6:6 --------------------------------------------------------------------
2+
6 | f(x = 2) // warn
3+
| ^^^^^
4+
| naming parameter x is deprecated

tests/warn/i19077.scala

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//> using options -deprecation
2+
3+
def f(@deprecatedName x: Int) = x * 2
4+
5+
@main def Test =
6+
f(x = 2) // warn

0 commit comments

Comments
 (0)