summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2009-11-20 21:02:23 +0000
committerMartin Odersky <odersky@gmail.com>2009-11-20 21:02:23 +0000
commitb408d0e98f694add637fc867433c627ca3191062 (patch)
treed13ca7c02e122ae53941c04523073a3ce7b1ea1e
parent937872a48956c11c278839622d5514a3ed65e25d (diff)
downloadscala-b408d0e98f694add637fc867433c627ca3191062.tar.gz
scala-b408d0e98f694add637fc867433c627ca3191062.tar.bz2
scala-b408d0e98f694add637fc867433c627ca3191062.zip
Closed #2642
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Infer.scala5
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala3
-rw-r--r--test/files/neg/bug875.check4
-rw-r--r--test/files/neg/bug875.scala6
4 files changed, 11 insertions, 7 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Infer.scala b/src/compiler/scala/tools/nsc/typechecker/Infer.scala
index a4b164edfe..3b2f917a05 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Infer.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Infer.scala
@@ -1620,7 +1620,7 @@ trait Infer {
* assignment expression.
*/
def inferMethodAlternative(tree: Tree, undetparams: List[Symbol],
- argtpes: List[Type], pt0: Type): Unit = tree.tpe match {
+ argtpes: List[Type], pt0: Type, varArgsOnly: Boolean = false): Unit = tree.tpe match {
case OverloadedType(pre, alts) =>
val pt = if (pt0.typeSymbol == UnitClass) WildcardType else pt0
tryTwice {
@@ -1631,6 +1631,9 @@ trait Infer {
var allApplicable = alts filter (alt =>
isApplicable(undetparams, followApply(pre.memberType(alt)), argtpes, pt))
+ if (varArgsOnly)
+ allApplicable = allApplicable filter (alt => isVarArgs(alt.tpe.paramTypes))
+
// if there are multiple, drop those that use a default
// (keep those that use vararg / tupling conversion)
val applicable =
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
index ff57aabcb2..1a8db1f27d 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
@@ -2182,7 +2182,8 @@ trait Typers { self: Analyzer =>
arg1
}
context.undetparams = undetparams
- inferMethodAlternative(fun, undetparams, argtpes.toList, pt)
+ inferMethodAlternative(fun, undetparams, argtpes.toList, pt,
+ varArgsOnly = args.nonEmpty && treeInfo.isWildcardStarArg(args.last))
doTypedApply(tree, adapt(fun, funMode(mode), WildcardType), args1, mode, pt)
case mt @ MethodType(params, _) =>
diff --git a/test/files/neg/bug875.check b/test/files/neg/bug875.check
index d547c8d69c..16a982241e 100644
--- a/test/files/neg/bug875.check
+++ b/test/files/neg/bug875.check
@@ -4,8 +4,8 @@ bug875.scala:3: error: no `: _*' annotation allowed here
^
bug875.scala:6: error: no `: _*' annotation allowed here
(such annotations are only allowed in arguments to *-parameters)
- mkList(xs: _*)
- ^
+ mkList1(xs: _*)
+ ^
bug875.scala:15: error: no `: _*' annotation allowed here
(such annotations are only allowed in arguments to *-parameters)
f(true, 1, xs: _*)
diff --git a/test/files/neg/bug875.scala b/test/files/neg/bug875.scala
index 9c579b0166..38affd5a43 100644
--- a/test/files/neg/bug875.scala
+++ b/test/files/neg/bug875.scala
@@ -1,9 +1,9 @@
object Test extends Application {
val xs = List(4, 5, 6)
val ys = List(1, 2, 3, xs: _*)
- def mkList(x: Int) = List(x)
- def mkList(x: Boolean) = List(x)
- mkList(xs: _*)
+ def mkList1(x: Int) = List(x)
+ def mkList2(x: Boolean) = List(x)
+ mkList1(xs: _*)
def f(x: Int*) = List(x: _*)