diff --git a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala b/src/compiler/scala/tools/nsc/typechecker/Implicits.scala index 2d759271b0ef..ec8b35bb523d 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Implicits.scala @@ -1823,8 +1823,9 @@ trait Implicits { // check the message's syntax: should be a string literal that may contain occurrences of the string "${X}", // where `X` refers to a type parameter of `sym` def check(sym: Symbol): Option[String] = - sym.getAnnotation(clazz).flatMap(_.stringArg(0) match { - case Some(m) => new Message(sym, m, annotationName).validate + sym.getAnnotation(clazz).flatMap(a => a.stringArg(0).orElse(a.assocs.headOption) match { + case Some(m: String) => new Message(sym, m, annotationName).validate // temporary, until we make implicitAmbiguous also a ConstantAnnotation + case Some((_, LiteralAnnotArg(Constant(m: String)))) => new Message(sym, m, annotationName).validate case None => Some(s"Missing argument `msg` on $annotationName annotation.") }) } diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index a3bfd7fd00da..72f530283aab 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -4043,8 +4043,13 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper val nvPairs = namedArgs map { case arg @ NamedArg(Ident(name), rhs) => - val sym = if (isJava) annScopeJava.lookup(name) - else findSymbol(typedFun.tpe.params)(_.name == name) + val sym = + if (isJava) annScopeJava.lookup(name) + else findSymbol(typedFun.tpe.params)(p => p.name == name || p.deprecatedParamName.contains(name).tap(r => if (r) { + val sinceVersion = p.deprecatedParamVersion.getOrElse("") + val since = if (sinceVersion.isEmpty) "" else s" since $sinceVersion" + context.deprecationWarning(arg.pos, p, s"the parameter name $name is deprecated$since: use `${p.name}` instead", sinceVersion) + })) if (sym == NoSymbol) { reportAnnotationError(UnknownAnnotationNameError(arg, name)) (nme.ERROR, None) diff --git a/src/library/scala/annotation/implicitNotFound.scala b/src/library/scala/annotation/implicitNotFound.scala index cad18eafb94f..b38e5a47322e 100644 --- a/src/library/scala/annotation/implicitNotFound.scala +++ b/src/library/scala/annotation/implicitNotFound.scala @@ -55,4 +55,4 @@ package scala.annotation * * @param msg The custom error message, must be a literal value. */ -final class implicitNotFound(value: String) extends scala.annotation.ConstantAnnotation +final class implicitNotFound(@deprecatedName(name = "msg", since = "2.13.5") value: String) extends scala.annotation.ConstantAnnotation diff --git a/test/files/neg/names-defaults-neg-warn.check b/test/files/neg/names-defaults-neg-warn.check index 2a05c49709d3..a9c1f2c621b1 100644 --- a/test/files/neg/names-defaults-neg-warn.check +++ b/test/files/neg/names-defaults-neg-warn.check @@ -1,14 +1,14 @@ -names-defaults-neg-warn.scala:25: error: unknown parameter name: x +names-defaults-neg-warn.scala:28: error: unknown parameter name: x Note that assignments in argument position are no longer allowed since Scala 2.13. To express the assignment expression, wrap it in brackets, e.g., `{ x = ... }`. f2(x = 1) // 2.12: deprecation warning, compiles. 2.13: error, no parameter named x ^ -names-defaults-neg-warn.scala:36: error: unknown parameter name: x +names-defaults-neg-warn.scala:39: error: unknown parameter name: x Note that assignments in argument position are no longer allowed since Scala 2.13. To express the assignment expression, wrap it in brackets, e.g., `{ x = ... }`. synchronized(x = 1) // deprecation warning in 2.12, error in 2.13 ^ -names-defaults-neg-warn.scala:45: error: unknown parameter name: x +names-defaults-neg-warn.scala:48: error: unknown parameter name: x f2(x = 1) // 2.12, 2.13: error (no such parameter). no deprecation warning in 2.12, x is not a variable. ^ names-defaults-neg-warn.scala:13: warning: the parameter name s is deprecated: use x instead @@ -17,5 +17,8 @@ names-defaults-neg-warn.scala:13: warning: the parameter name s is deprecated: u names-defaults-neg-warn.scala:14: warning: the parameter name x is deprecated: use s instead deprNam2.g(x = "dlkjf") ^ -2 warnings +names-defaults-neg-warn.scala:17: warning: the parameter name x is deprecated since 1.2.3: use `y` instead + @annot(x = 1) def ann1 = 0 + ^ +3 warnings 3 errors diff --git a/test/files/neg/names-defaults-neg-warn.scala b/test/files/neg/names-defaults-neg-warn.scala index 3ecd909eaa2f..c66473039d54 100644 --- a/test/files/neg/names-defaults-neg-warn.scala +++ b/test/files/neg/names-defaults-neg-warn.scala @@ -1,4 +1,4 @@ -// scalac: -deprecation -Xfatal-warnings +// scalac: -deprecation -Werror // object Test extends App { object deprNam2 { @@ -13,6 +13,9 @@ object Test extends App { deprNam2.f(s = "dlfkj") deprNam2.g(x = "dlkjf") deprNam2.g(s = new Object) + + @annot(x = 1) def ann1 = 0 + @annot(y = 1) def ann2 = 0 } class C { @@ -45,3 +48,5 @@ class C { f2(x = 1) // 2.12, 2.13: error (no such parameter). no deprecation warning in 2.12, x is not a variable. } } + +class annot(@deprecatedName("x", "1.2.3") y: Int) extends annotation.ConstantAnnotation