diff options
author | Som Snytt <som.snytt@gmail.com> | 2013-09-29 13:46:02 -0700 |
---|---|---|
committer | Som Snytt <som.snytt@gmail.com> | 2015-02-08 22:25:43 -0800 |
commit | 40bef79974de3ed00f0173a65fdf7aa19170900e (patch) | |
tree | dfb108e9332ec522ea60efb4fac4b117b2674f85 /src | |
parent | 178e8df9b6a91375a6162721a0cbc2d90bcc7451 (diff) | |
download | scala-40bef79974de3ed00f0173a65fdf7aa19170900e.tar.gz scala-40bef79974de3ed00f0173a65fdf7aa19170900e.tar.bz2 scala-40bef79974de3ed00f0173a65fdf7aa19170900e.zip |
SI-9140 Allow deprecating current parameter name
Allow deprecatedName to specify the name of the parameter
it qualifies.
This tells the user, That's my name, don't wear it out.
I.e., don't use my name when calling me.
Use cases include: the name will change; normally a name
should be provided for a boolean, but not in this case
(perhaps because there is only one argument).
```
scala> def f(@deprecatedName('foo) bar: String) = bar.reverse
f: (bar: String)String
scala> f(foo = "hello")
<console>:9: warning: the parameter name foo has been deprecated. Use bar instead.
f(foo = "hello")
^
res0: String = olleh
scala> def g(@deprecatedName('foo) foo: String) = foo.reverse
g: (foo: String)String
scala> g(foo = "hello")
<console>:9: warning: naming parameter foo has been deprecated.
g(foo = "hello")
^
res1: String = olleh
```
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala | 24 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Typers.scala | 2 |
2 files changed, 17 insertions, 9 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala b/src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala index 50f658f68d..119b415d51 100644 --- a/src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala +++ b/src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala @@ -9,6 +9,7 @@ package typechecker import symtab.Flags._ import scala.collection.mutable import scala.reflect.ClassTag +import PartialFunction.{ cond => when } /** * @author Lukas Rytz @@ -552,15 +553,22 @@ trait NamesDefaults { self: Analyzer => val namelessArgs = mapWithIndex(args) { (arg, argIndex) => arg match { case arg @ AssignOrNamedArg(Ident(name), rhs) => - def matchesName(param: Symbol) = !param.isSynthetic && ( - (param.name == name) || (param.deprecatedParamName match { - case Some(`name`) => - context0.deprecationWarning(arg.pos, param, + def matchesName(param: Symbol) = { + def checkDeprecation = when(param.deprecatedParamName) { case Some(`name`) => true } + def checkName = { + val res = param.name == name + if (res && checkDeprecation) + context0.deprecationWarning(arg.pos, param, s"naming parameter $name has been deprecated.") + res + } + def checkAltName = { + val res = checkDeprecation + if (res) context0.deprecationWarning(arg.pos, param, s"the parameter name $name has been deprecated. Use ${param.name} instead.") - true - case _ => false - }) - ) + res + } + !param.isSynthetic && (checkName || checkAltName) + } val paramPos = params indexWhere matchesName if (paramPos == -1) { if (positionalAllowed) { diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 2dd79075ee..baa09bb14e 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -2214,7 +2214,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper val allParams = meth.paramss.flatten for (p <- allParams) { for (n <- p.deprecatedParamName) { - if (allParams.exists(p1 => p1.name == n || (p != p1 && p1.deprecatedParamName.exists(_ == n)))) + if (allParams.exists(p1 => p != p1 && (p1.name == n || p1.deprecatedParamName.exists(_ == n)))) DeprecatedParamNameError(p, n) } } |