summaryrefslogtreecommitdiff
path: root/src/compiler
diff options
context:
space:
mode:
authorAdriaan Moors <adriaan.moors@typesafe.com>2014-01-15 14:11:08 -0800
committerAdriaan Moors <adriaan.moors@typesafe.com>2014-01-15 14:11:08 -0800
commit0e8984100709658588c67d097452b8606c12d750 (patch)
treeb2fb27d6fc66320947de6d30a22a9d4d4d03e651 /src/compiler
parenta7de84d24aafb554019ebebff36a18c966568a30 (diff)
parentc5567e2700dfe6c19d968c2285821ef4ab8a8e6c (diff)
downloadscala-0e8984100709658588c67d097452b8606c12d750.tar.gz
scala-0e8984100709658588c67d097452b8606c12d750.tar.bz2
scala-0e8984100709658588c67d097452b8606c12d750.zip
Merge pull request #3260 from soc/SI-8035
Deprecate automatic () insertion in argument lists
Diffstat (limited to 'src/compiler')
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Adaptations.scala29
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)
}
}
}