Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SI-8417 Check adapts of each param section #5643

Merged
merged 1 commit into from Mar 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/compiler/scala/tools/nsc/typechecker/Adaptations.scala
Expand Up @@ -80,7 +80,9 @@ trait Adaptations {
context.deprecationWarning(t.pos, t.symbol, adaptWarningMessage(msg), "2.11.0")
}
} 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."))
context.warning(t.pos, adaptWarningMessage(
s"Adapting argument list by creating a ${args.size}-tuple: this may not be what you want.")
)

// return `true` if the adaptation should be kept
!(settings.noAdaptedArgs || (args.isEmpty && settings.future))
Expand Down
34 changes: 17 additions & 17 deletions src/compiler/scala/tools/nsc/typechecker/Typers.scala
Expand Up @@ -3426,29 +3426,29 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
// repeat vararg as often as needed, remove by-name
val formals = formalTypes(paramTypes, argslen)

/* Try packing all arguments into a Tuple and apply `fun`
* to that. This is the last thing which is tried (after
* default arguments)
/* Try packing all arguments into a Tuple and apply `fun` to that.
* This is the last thing which is tried (after default arguments).
*/
def tryTupleApply: Tree = {
if (eligibleForTupleConversion(paramTypes, argslen) && !phase.erasedTypes) {
def tryTupleApply: Tree =
if (phase.erasedTypes || !eligibleForTupleConversion(paramTypes, argslen)) EmptyTree
else {
val tupleArgs = List(atPos(tree.pos.makeTransparent)(gen.mkTuple(args)))
// expected one argument, but got 0 or >1 ==> try applying to tuple
// the inner "doTypedApply" does "extractUndetparams" => restore when it fails
val savedUndetparams = context.undetparams
silent(_.doTypedApply(tree, fun, tupleArgs, mode, pt)) map { t =>
// Depending on user options, may warn or error here if
// a Unit or tuple was inserted.
val keepTree = (
!mode.typingExprNotFun // why? introduced in 4e488a60, doc welcome
|| t.symbol == null // ditto
|| checkValidAdaptation(t, args)
)
if (keepTree) t else EmptyTree
} orElse { _ => context.undetparams = savedUndetparams ; EmptyTree }
// May warn or error if a Unit or tuple was inserted.
def validate(t: Tree): Tree = {
// regardless of typer's mode
val invalidAdaptation = t.symbol != null && !checkValidAdaptation(t, args)
// only bail if we're typing an expression (and not inside another application)
if (invalidAdaptation && mode.typingExprNotFun) EmptyTree else t
}
def reset(errors: Seq[AbsTypeError]): Tree = {
context.undetparams = savedUndetparams
EmptyTree
}
silent(_.doTypedApply(tree, fun, tupleArgs, mode, pt)).map(validate).orElse(reset)
}
else EmptyTree
}

/* Treats an application which uses named or default arguments.
* Also works if names + a vararg used: when names are used, the vararg
Expand Down
15 changes: 15 additions & 0 deletions test/files/neg/t8417.check
@@ -0,0 +1,15 @@
t8417.scala:5: warning: Adapting argument list by creating a 2-tuple: this may not be what you want.
signature: T.f(x: Any)(y: Any): String
given arguments: "hello", "world"
after adaptation: T.f(("hello", "world"): (String, String))
def g = f("hello", "world")("holy", "moly")
^
t8417.scala:5: warning: Adapting argument list by creating a 2-tuple: this may not be what you want.
signature: T.f(x: Any)(y: Any): String
given arguments: "holy", "moly"
after adaptation: T.f(("holy", "moly"): (String, String))
def g = f("hello", "world")("holy", "moly")
^
error: No warnings can be incurred under -Xfatal-warnings.
two warnings found
one error found
1 change: 1 addition & 0 deletions test/files/neg/t8417.flags
@@ -0,0 +1 @@
-Xfatal-warnings -Ywarn-adapted-args
6 changes: 6 additions & 0 deletions test/files/neg/t8417.scala
@@ -0,0 +1,6 @@


trait T {
def f(x: Any)(y: Any) = "" + x + y
def g = f("hello", "world")("holy", "moly")
}