summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala7
-rw-r--r--test/files/neg/names-defaults-neg.check44
-rw-r--r--test/files/neg/names-defaults-neg.scala2
3 files changed, 32 insertions, 21 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala b/src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala
index f8dd35cfdd..34f832f2a6 100644
--- a/src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala
@@ -372,7 +372,12 @@ trait NamesDefaults { self: Analyzer =>
// var x = 0
// f(x = 1) << "x = 1" typechecks with expected type WildcardType
val udp = typer.context.extractUndetparams()
- val subst = new SubstTypeMap(udp, udp map (_ => WildcardType))
+ val subst = new SubstTypeMap(udp, udp map (_ => WildcardType)) {
+ override def apply(tp: Type): Type = tp match {
+ case TypeRef(_, sym, List(arg)) if (sym == ByNameParamClass) => super.apply(arg)
+ case _ => super.apply(tp)
+ }
+ }
val res = typer.silent(_.typed(arg, subst(paramtpe))) match {
case _: TypeError =>
positionalAllowed = false
diff --git a/test/files/neg/names-defaults-neg.check b/test/files/neg/names-defaults-neg.check
index 5a12d51764..0a1ddf8286 100644
--- a/test/files/neg/names-defaults-neg.check
+++ b/test/files/neg/names-defaults-neg.check
@@ -1,4 +1,4 @@
-names-defaults-neg.scala:65: error: not enough arguments for method apply: (a: Int,b: String)(c: Int*)Fact in object Fact.
+names-defaults-neg.scala:66: error: not enough arguments for method apply: (a: Int,b: String)(c: Int*)Fact in object Fact.
Unspecified value parameter b.
val fac = Fact(1)(2, 3)
^
@@ -29,85 +29,89 @@ names-defaults-neg.scala:18: error: not found: value m
names-defaults-neg.scala:19: error: not found: value m
test7 { m = 1 } // no named arguments in argument block
^
-names-defaults-neg.scala:22: error: parameter specified twice: a
+names-defaults-neg.scala:20: error: reference to x is ambiguous; it is both, a parameter
+name of the method and the name of a variable currently in scope.
+ test8(x = 1)
+ ^
+names-defaults-neg.scala:23: error: parameter specified twice: a
test1(1, a = 2)
^
-names-defaults-neg.scala:23: error: parameter specified twice: b
+names-defaults-neg.scala:24: error: parameter specified twice: b
test1(b = 1, b = "2")
^
-names-defaults-neg.scala:26: error: {
+names-defaults-neg.scala:27: error: {
val x$1: Int(3) = 3;
val x$2: Int(1) = 1;
Test.this.test3(1, 3)
} of type Int does not take parameters
test3(b = 3, a = 1)(3)
^
-names-defaults-neg.scala:35: error: ambiguous reference to overloaded definition,
+names-defaults-neg.scala:36: error: ambiguous reference to overloaded definition,
both method f in object t1 of type (b: String,a: Int)java.lang.String
and method f in object t1 of type (a: Int,b: String)java.lang.String
match argument types (b: java.lang.String,a: Int)
t1.f(b = "dkljf", a = 1)
^
-names-defaults-neg.scala:42: error: ambiguous reference to overloaded definition,
+names-defaults-neg.scala:43: error: ambiguous reference to overloaded definition,
both method f in object t3 of type (a2: Int)(b: Int)java.lang.String
and method f in object t3 of type (a1: Int)java.lang.String
match argument types (Int)
t3.f(1)
^
-names-defaults-neg.scala:43: error: ambiguous reference to overloaded definition,
+names-defaults-neg.scala:44: error: ambiguous reference to overloaded definition,
both method f in object t3 of type (a2: Int)(b: Int)java.lang.String
and method f in object t3 of type (a1: Int)java.lang.String
match argument types (Int)
t3.f(1)(2)
^
-names-defaults-neg.scala:49: error: ambiguous reference to overloaded definition,
+names-defaults-neg.scala:50: error: ambiguous reference to overloaded definition,
both method g in object t7 of type (a: B)java.lang.String
and method g in object t7 of type (a: C,b: Int*)java.lang.String
match argument types (C)
t7.g(new C()) // ambigous reference
^
-names-defaults-neg.scala:53: error: parameter specified twice: b
+names-defaults-neg.scala:54: error: parameter specified twice: b
test5(a = 1, b = "dkjl", b = "dkj")
^
-names-defaults-neg.scala:54: error: parameter specified twice: b
+names-defaults-neg.scala:55: error: parameter specified twice: b
test5(1, "2", b = 3)
^
-names-defaults-neg.scala:55: error: when using named arguments, the vararg parameter has to be specified exactly once
+names-defaults-neg.scala:56: error: when using named arguments, the vararg parameter has to be specified exactly once
test5(b = "dlkj")
^
-names-defaults-neg.scala:61: error: ambiguous reference to overloaded definition,
+names-defaults-neg.scala:62: error: ambiguous reference to overloaded definition,
both method f in object t8 of type (b: String,a: Int)java.lang.String
and method f in object t8 of type (a: Int,b: java.lang.Object)java.lang.String
match argument types (a: Int,b: java.lang.String) and expected result type Any
println(t8.f(a = 0, b = "1")) // ambigous reference
^
-names-defaults-neg.scala:69: error: wrong number of arguments for <none>: (x: Int,y: String)A1
+names-defaults-neg.scala:70: error: wrong number of arguments for <none>: (x: Int,y: String)A1
A1() match { case A1(_) => () }
^
-names-defaults-neg.scala:76: error: inferred kinds of the type arguments (List[Int]) do not conform to the expected kinds of the type parameters (type T).
+names-defaults-neg.scala:77: error: inferred kinds of the type arguments (List[Int]) do not conform to the expected kinds of the type parameters (type T).
List[Int]'s type parameters do not match type T's expected parameters: class List has one type parameter, but type T has one
test4()
^
error: type mismatch;
found : List[Int]
required: List[List[List[List[X forSome { type X }]]]]
-names-defaults-neg.scala:79: error: type mismatch;
+names-defaults-neg.scala:80: error: type mismatch;
found : List[Int]
required: List[List[?]]
def test6[T](x: List[List[T]] = List(1,2)) = x
^
-names-defaults-neg.scala:82: error: type mismatch;
+names-defaults-neg.scala:83: error: type mismatch;
found : Int
required: String
new A2[String]()
^
-names-defaults-neg.scala:93: error: multiple overloaded alternatives of method foo define default arguments
+names-defaults-neg.scala:95: error: multiple overloaded alternatives of method foo define default arguments
def foo(a: Int = 0) = a
^
-names-defaults-neg.scala:103: error: multiple overloaded alternatives of method foo define default arguments
+names-defaults-neg.scala:105: error: multiple overloaded alternatives of method foo define default arguments
override def foo(a: Int = 1092) = a
^
-names-defaults-neg.scala:106: error: multiple overloaded alternatives of method bar define default arguments
+names-defaults-neg.scala:108: error: multiple overloaded alternatives of method bar define default arguments
def bar(i: Int = 129083) = i
^
-28 errors found
+29 errors found
diff --git a/test/files/neg/names-defaults-neg.scala b/test/files/neg/names-defaults-neg.scala
index 523d8977ff..cf149d4b31 100644
--- a/test/files/neg/names-defaults-neg.scala
+++ b/test/files/neg/names-defaults-neg.scala
@@ -17,6 +17,7 @@ object Test extends Application {
test7((m = 1)) // named arguments must be top-level assignments
test7({m = 1})
test7 { m = 1 } // no named arguments in argument block
+ test8(x = 1)
// argument specified twice
test1(1, a = 2)
@@ -86,6 +87,7 @@ object Test extends Application {
def test2(x: Unit) = println("test2")
def test3(a: Int, b: Int) = a + b
def test7(m: Int) = m
+ def test8[T](x: => T) = println("test8")
}
// only one overloaded alternative is allowed to have defaults