diff options
author | Simon Ochsenreither <simon@ochsenreither.de> | 2013-12-10 20:11:07 +0100 |
---|---|---|
committer | Simon Ochsenreither <simon@ochsenreither.de> | 2014-01-09 00:43:14 +0100 |
commit | c5567e2700dfe6c19d968c2285821ef4ab8a8e6c (patch) | |
tree | 6a120e3ec4d31224fd3f36956824b1a23944dee7 /src/compiler | |
parent | ada8d9156baad2d8a24c1a40e032eb4bc7154bac (diff) | |
download | scala-c5567e2700dfe6c19d968c2285821ef4ab8a8e6c.tar.gz scala-c5567e2700dfe6c19d968c2285821ef4ab8a8e6c.tar.bz2 scala-c5567e2700dfe6c19d968c2285821ef4ab8a8e6c.zip |
SI-8035 Deprecate automatic () insertion in argument lists
This promotes the () insertion warning from -Ywarn-adapted-args to a
deprecation warning. -Xfuture tunrs it into a compiler error.
Auto tupling remains unchanged for now.
The tests have been fixed the following way:
- Warnings caused by general sloppiness (Try(), Future(), ...) have been
fixed.
- Warnings which raise interesting questions (x == (), ...) received an
updated checkfile for now.
Diffstat (limited to 'src/compiler')
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Adaptations.scala | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Adaptations.scala b/src/compiler/scala/tools/nsc/typechecker/Adaptations.scala index 0b5b0759b2..1e544e54f6 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Adaptations.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Adaptations.scala @@ -43,11 +43,11 @@ trait Adaptations { def givenString = if (args.isEmpty) "<none>" else args.mkString(", ") def adaptedArgs = if (args.isEmpty) "(): Unit" else args.mkString("(", ", ", "): " + applyArg.tpe) - def adaptWarning(msg: String) = context.warning(t.pos, msg + + def adaptWarningMessage(msg: String, showAdaptation: Boolean = true) = msg + "\n signature: " + sigString + "\n given arguments: " + givenString + - "\n after adaptation: " + callString + "(" + adaptedArgs + ")" - ) + (if (showAdaptation) "\n after adaptation: " + callString + "(" + adaptedArgs + ")" else "") + // A one-argument method accepting Object (which may look like "Any" // at this point if the class is java defined) is a "leaky target" for // which we should be especially reluctant to insert () or auto-tuple. @@ -69,17 +69,20 @@ trait Adaptations { } if (settings.noAdaptedArgs) - adaptWarning("No automatic adaptation here: use explicit parentheses.") - else if (settings.warnAdaptedArgs) - adaptWarning( - if (args.isEmpty) "Adapting argument list by inserting (): " + ( - if (isLeakyTarget) "leaky (Object-receiving) target makes this especially dangerous." - else "this is unlikely to be what you want." - ) - else "Adapting argument list by creating a " + args.size + "-tuple: this may not be what you want." - ) + context.warning(t.pos, adaptWarningMessage("No automatic adaptation here: use explicit parentheses.")) + else if (args.isEmpty) { + if (settings.future) + context.error(t.pos, adaptWarningMessage("Adaptation of argument list by inserting () has been removed.", showAdaptation = false)) + else { + val msg = "Adaptation of argument list by inserting () has been deprecated: " + ( + if (isLeakyTarget) "leaky (Object-receiving) target makes this especially dangerous." + else "this is unlikely to be what you want.") + context.unit.deprecationWarning(t.pos, adaptWarningMessage(msg)) + } + } else if (settings.warnAdaptedArgs) + context.warning(t.pos, adaptWarningMessage(s"Adapting argument list by creating a ${args.size}-tuple: this may not be what you want.")) - !settings.noAdaptedArgs + !settings.noAdaptedArgs || !(args.isEmpty && settings.future) } } } |