summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSom Snytt <som.snytt@gmail.com>2015-02-09 13:01:30 -0800
committerSom Snytt <som.snytt@gmail.com>2015-02-09 13:01:30 -0800
commite1c6f0eacd5372e5ee4fe267c6c5b7124cd162f3 (patch)
tree56a227d57c7251bf3f087ea28fed4fd90f352e75 /src
parent40bef79974de3ed00f0173a65fdf7aa19170900e (diff)
downloadscala-e1c6f0eacd5372e5ee4fe267c6c5b7124cd162f3.tar.gz
scala-e1c6f0eacd5372e5ee4fe267c6c5b7124cd162f3.tar.bz2
scala-e1c6f0eacd5372e5ee4fe267c6c5b7124cd162f3.zip
SI-9140 Allow omitting pleonastic parameter name
Enable simply: ``` scala> def f(@deprecatedName foo: String) = foo.reverse f: (foo: String)String scala> f(foo = "bar") <console>:9: warning: naming parameter foo has been deprecated. f(foo = "bar") ^ res0: String = rab ``` `Symbol.deprecatedParamName` conventionally returns `NO_NAME` when the name is omitted.
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala10
-rw-r--r--src/library/scala/deprecatedName.scala4
-rw-r--r--src/reflect/scala/reflect/internal/Symbols.scala2
3 files changed, 11 insertions, 5 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala b/src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala
index 119b415d51..ba4c962f34 100644
--- a/src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala
@@ -554,15 +554,19 @@ trait NamesDefaults { self: Analyzer =>
arg match {
case arg @ AssignOrNamedArg(Ident(name), rhs) =>
def matchesName(param: Symbol) = {
- def checkDeprecation = when(param.deprecatedParamName) { case Some(`name`) => true }
+ def checkDeprecation(anonOK: Boolean) =
+ when (param.deprecatedParamName) {
+ case Some(`name`) => true
+ case Some(nme.NO_NAME) => anonOK
+ }
def checkName = {
val res = param.name == name
- if (res && checkDeprecation)
+ if (res && checkDeprecation(true))
context0.deprecationWarning(arg.pos, param, s"naming parameter $name has been deprecated.")
res
}
def checkAltName = {
- val res = checkDeprecation
+ val res = checkDeprecation(false)
if (res) context0.deprecationWarning(arg.pos, param,
s"the parameter name $name has been deprecated. Use ${param.name} instead.")
res
diff --git a/src/library/scala/deprecatedName.scala b/src/library/scala/deprecatedName.scala
index 07c5c8925c..a0d3aa829b 100644
--- a/src/library/scala/deprecatedName.scala
+++ b/src/library/scala/deprecatedName.scala
@@ -29,4 +29,6 @@ import scala.annotation.meta._
* @since 2.8.1
*/
@param
-class deprecatedName(name: Symbol) extends scala.annotation.StaticAnnotation
+class deprecatedName(name: Symbol) extends scala.annotation.StaticAnnotation {
+ def this() = this(Symbol("<none>"))
+}
diff --git a/src/reflect/scala/reflect/internal/Symbols.scala b/src/reflect/scala/reflect/internal/Symbols.scala
index f2aa14b866..293af68c5f 100644
--- a/src/reflect/scala/reflect/internal/Symbols.scala
+++ b/src/reflect/scala/reflect/internal/Symbols.scala
@@ -858,7 +858,7 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
def isDeprecated = hasAnnotation(DeprecatedAttr)
def deprecationMessage = getAnnotation(DeprecatedAttr) flatMap (_ stringArg 0)
def deprecationVersion = getAnnotation(DeprecatedAttr) flatMap (_ stringArg 1)
- def deprecatedParamName = getAnnotation(DeprecatedNameAttr) flatMap (_ symbolArg 0)
+ def deprecatedParamName = getAnnotation(DeprecatedNameAttr) flatMap (_ symbolArg 0 orElse Some(nme.NO_NAME))
def hasDeprecatedInheritanceAnnotation
= hasAnnotation(DeprecatedInheritanceAttr)
def deprecatedInheritanceMessage