summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukas Rytz <lukas.rytz@epfl.ch>2010-09-03 14:20:07 +0000
committerLukas Rytz <lukas.rytz@epfl.ch>2010-09-03 14:20:07 +0000
commitb3256eda6631fc0db5bb9440a6b77e2186053b3f (patch)
tree67de4c2d53b8c381bd8f04da77b305e7ce8256af
parent0d8ba6ca381227101367fce68ce8e250c4d91e33 (diff)
downloadscala-b3256eda6631fc0db5bb9440a6b77e2186053b3f.tar.gz
scala-b3256eda6631fc0db5bb9440a6b77e2186053b3f.tar.bz2
scala-b3256eda6631fc0db5bb9440a6b77e2186053b3f.zip
better error message for default arguments.
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala3
-rw-r--r--test/files/neg/names-defaults-neg.check29
-rw-r--r--test/files/neg/names-defaults-neg.scala4
3 files changed, 23 insertions, 13 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
index a003a4fd7e..7dc2f56197 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
@@ -2371,6 +2371,9 @@ trait Typers { self: Analyzer =>
val funSym = fun1 match { case Block(_, expr) => expr.symbol }
if (allArgs.length != args.length && callToCompanionConstr(context, funSym)) {
errorTree(tree, "module extending its companion class cannot use default constructor arguments")
+ } else if (allArgs.length > formals.length) {
+ removeNames(Typer.this)(allArgs, params) // #3818
+ setError(tree)
} else if (allArgs.length == formals.length) {
// useful when a default doesn't match parameter type, e.g. def f[T](x:T="a"); f[Int]()
val note = "Error occurred in an application involving default arguments."
diff --git a/test/files/neg/names-defaults-neg.check b/test/files/neg/names-defaults-neg.check
index 1f77b828b7..743496e0e1 100644
--- a/test/files/neg/names-defaults-neg.check
+++ b/test/files/neg/names-defaults-neg.check
@@ -119,44 +119,47 @@ names-defaults-neg.scala:93: warning: the parameter name y has been deprecated.
names-defaults-neg.scala:93: error: parameter specified twice: b
deprNam3(y = 10, b = 2)
^
-names-defaults-neg.scala:127: error: reference to var2 is ambiguous; it is both, a parameter
+names-defaults-neg.scala:98: error: unknown parameter name: m
+ f3818(y = 1, m = 1)
+ ^
+names-defaults-neg.scala:131: error: reference to var2 is ambiguous; it is both, a parameter
name of the method and the name of a variable currently in scope.
delay(var2 = 40)
^
-names-defaults-neg.scala:130: error: missing parameter type for expanded function ((x$1) => a = x$1)
+names-defaults-neg.scala:134: error: missing parameter type for expanded function ((x$1) => a = x$1)
val taf2: Int => Unit = testAnnFun(a = _, b = get("+"))
^
-names-defaults-neg.scala:131: error: parameter specified twice: a
+names-defaults-neg.scala:135: error: parameter specified twice: a
val taf3 = testAnnFun(b = _: String, a = get(8))
^
-names-defaults-neg.scala:132: error: wrong number of parameters; expected = 2
+names-defaults-neg.scala:136: error: wrong number of parameters; expected = 2
val taf4: (Int, String) => Unit = testAnnFun(_, b = _)
^
-names-defaults-neg.scala:140: error: variable definition needs type because the name is used as named argument the definition.
+names-defaults-neg.scala:144: error: variable definition needs type because the name is used as named argument the definition.
def t3 { var x = t.f(x = 1) }
^
-names-defaults-neg.scala:143: error: variable definition needs type because the name is used as named argument the definition.
+names-defaults-neg.scala:147: error: variable definition needs type because the name is used as named argument the definition.
object t6 { var x = t.f(x = 1) }
^
-names-defaults-neg.scala:146: error: variable definition needs type because the name is used as named argument the definition.
+names-defaults-neg.scala:150: error: variable definition needs type because the name is used as named argument the definition.
class t9 { var x = t.f(x = 1) }
^
-names-defaults-neg.scala:160: error: variable definition needs type because the name is used as named argument the definition.
+names-defaults-neg.scala:164: error: variable definition needs type because the name is used as named argument the definition.
def u3 { var x = u.f(x = 1) }
^
-names-defaults-neg.scala:163: error: variable definition needs type because the name is used as named argument the definition.
+names-defaults-neg.scala:167: error: variable definition needs type because the name is used as named argument the definition.
def u6 { var x = u.f(x = "32") }
^
-names-defaults-neg.scala:166: error: reference to x is ambiguous; it is both, a parameter
+names-defaults-neg.scala:170: error: reference to x is ambiguous; it is both, a parameter
name of the method and the name of a variable currently in scope.
def u9 { var x: Int = u.f(x = 1) }
^
-names-defaults-neg.scala:173: error: variable definition needs type because the name is used as named argument the definition.
+names-defaults-neg.scala:177: error: variable definition needs type because the name is used as named argument the definition.
class u15 { var x = u.f(x = 1) }
^
-names-defaults-neg.scala:176: error: reference to x is ambiguous; it is both, a parameter
+names-defaults-neg.scala:180: error: reference to x is ambiguous; it is both, a parameter
name of the method and the name of a variable currently in scope.
class u18 { var x: Int = u.f(x = 1) }
^
one warning found
-40 errors found
+41 errors found
diff --git a/test/files/neg/names-defaults-neg.scala b/test/files/neg/names-defaults-neg.scala
index 4350f9860d..9fbe554f0e 100644
--- a/test/files/neg/names-defaults-neg.scala
+++ b/test/files/neg/names-defaults-neg.scala
@@ -93,6 +93,10 @@ object Test extends Application {
deprNam3(y = 10, b = 2)
+ // t3818
+ def f3818(x: Int = 1, y: Int, z: Int = 1) = 0
+ f3818(y = 1, m = 1)
+
// DEFINITIONS
def test1(a: Int, b: String) = a +": "+ b
def test2(x: Unit) = println("test2")