summaryrefslogtreecommitdiff
path: root/test/files/neg
diff options
context:
space:
mode:
authorLukas Rytz <lukas.rytz@epfl.ch>2009-05-30 07:36:31 +0000
committerLukas Rytz <lukas.rytz@epfl.ch>2009-05-30 07:36:31 +0000
commit390ccacfe0caa4c07af6193dec3e172c0fcd7896 (patch)
tree001ff4a00bd9d8cab651d9bf245bfc795748d829 /test/files/neg
parent661f1ba10e5062fd987c4cafe43ad1f0dc3f5491 (diff)
downloadscala-390ccacfe0caa4c07af6193dec3e172c0fcd7896.tar.gz
scala-390ccacfe0caa4c07af6193dec3e172c0fcd7896.tar.bz2
scala-390ccacfe0caa4c07af6193dec3e172c0fcd7896.zip
Named and default arguments
- MethodTypes now have (params: List[Symbol]) - "copy"-methods for case classes - the "copy" object in the compiler is now called "treeCopy"
Diffstat (limited to 'test/files/neg')
-rw-r--r--test/files/neg/bug1112.check2
-rw-r--r--test/files/neg/bug1523.check2
-rw-r--r--test/files/neg/bug588.check12
-rw-r--r--test/files/neg/bug663.check6
-rw-r--r--test/files/neg/bug876.check2
-rw-r--r--test/files/neg/bug900.check4
-rw-r--r--test/files/neg/bug960.check4
-rw-r--r--test/files/neg/implicits.check4
-rw-r--r--test/files/neg/names-defaults-neg.check108
-rw-r--r--test/files/neg/names-defaults-neg.scala109
-rw-r--r--test/files/neg/overload.check4
-rw-r--r--test/files/neg/t0259.check6
-rw-r--r--test/files/neg/t0345.check2
-rw-r--r--test/files/neg/t1659.check5
-rw-r--r--test/files/neg/t1659.scala4
-rw-r--r--test/files/neg/viewtest.check4
16 files changed, 243 insertions, 35 deletions
diff --git a/test/files/neg/bug1112.check b/test/files/neg/bug1112.check
index 8daca9b4dc..d94dba9448 100644
--- a/test/files/neg/bug1112.check
+++ b/test/files/neg/bug1112.check
@@ -1,4 +1,4 @@
-bug1112.scala:12: error: wrong number of arguments for method call: (Int)(=> () => Unit)Unit
+bug1112.scala:12: error: too many arguments for method call: (p: Int)(f: => () => Unit)Unit
call(0,() => System.out.println("here we are"))
^
one error found
diff --git a/test/files/neg/bug1523.check b/test/files/neg/bug1523.check
index 6031985640..96d052fa4c 100644
--- a/test/files/neg/bug1523.check
+++ b/test/files/neg/bug1523.check
@@ -1,4 +1,4 @@
-bug1523.scala:4: error: wrong number of arguments for method bug: (Any)Any
+bug1523.scala:4: error: too many arguments for method bug: (x: Any)Any
def go() = bug("a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a")
^
one error found
diff --git a/test/files/neg/bug588.check b/test/files/neg/bug588.check
index f4129d62a2..d795922e0c 100644
--- a/test/files/neg/bug588.check
+++ b/test/files/neg/bug588.check
@@ -1,13 +1,13 @@
bug588.scala:3: error: double definition:
-method visit:((Int) => String)Boolean and
-method visit:((Int) => unit)Boolean at line 2
-have same type after erasure: (Function1)Boolean
+method visit:(f: (Int) => String)Boolean and
+method visit:(f: (Int) => unit)Boolean at line 2
+have same type after erasure: (f: Function1)Boolean
def visit(f: Int => String): Boolean
^
bug588.scala:10: error: double definition:
-method f:(Test.this.TypeB)Unit and
-method f:(Test.this.TypeA)Unit at line 9
-have same type after erasure: (Test#TraitA)Unit
+method f:(brac: Test.this.TypeB)Unit and
+method f:(node: Test.this.TypeA)Unit at line 9
+have same type after erasure: (brac: Test#TraitA)Unit
def f(brac : TypeB) : Unit;
^
two errors found
diff --git a/test/files/neg/bug663.check b/test/files/neg/bug663.check
index d1ef2ae09d..6ae7198f0d 100644
--- a/test/files/neg/bug663.check
+++ b/test/files/neg/bug663.check
@@ -1,7 +1,7 @@
bug663.scala:11: error: name clash between defined and inherited member:
-method asMatch:(Test.this.Node)Any and
-method asMatch:(Test.this.Matchable)Any in trait MatchableImpl
-have same type after erasure: (test.Test#NodeImpl)java.lang.Object
+method asMatch:(m: Test.this.Node)Any and
+method asMatch:(node: Test.this.Matchable)Any in trait MatchableImpl
+have same type after erasure: (m: test.Test#NodeImpl)java.lang.Object
def asMatch(m : Node) : Any = {
^
one error found
diff --git a/test/files/neg/bug876.check b/test/files/neg/bug876.check
index 5ad3f48379..e4be7e3351 100644
--- a/test/files/neg/bug876.check
+++ b/test/files/neg/bug876.check
@@ -1,4 +1,4 @@
-bug876.scala:25: error: wrong number of arguments for method apply: (AssertionError.A)manager.B in trait MapTemplate
+bug876.scala:25: error: too many arguments for method apply: (key: AssertionError.A)manager.B in trait MapTemplate
assert(manager.map(A2) == List(manager.map(A2, A1)))
^
one error found
diff --git a/test/files/neg/bug900.check b/test/files/neg/bug900.check
index 778bce7c9f..459ea38bc3 100644
--- a/test/files/neg/bug900.check
+++ b/test/files/neg/bug900.check
@@ -2,8 +2,8 @@ bug900.scala:4: error: type mismatch;
found : Foo.this.x.type (with underlying type Foo.this.bar)
required: AnyRef
Note that implicit conversions are not applicable because they are ambiguous:
- both method orderingToOrdered in object Predef of type [T](T)(implicit Ordering[T])Ordered[T]
- and method any2stringadd in object Predef of type (Any)scala.runtime.StringAdd
+ both method orderingToOrdered in object Predef of type [T](x: T)(implicit ord: Ordering[T])Ordered[T]
+ and method any2stringadd in object Predef of type (x: Any)scala.runtime.StringAdd
are possible conversion functions from Foo.this.x.type to AnyRef
def break(): x.type
^
diff --git a/test/files/neg/bug960.check b/test/files/neg/bug960.check
index e61394f2d0..ebfc3c6638 100644
--- a/test/files/neg/bug960.check
+++ b/test/files/neg/bug960.check
@@ -1,6 +1,6 @@
bug960.scala:18: error: ambiguous reference to overloaded definition,
-both method unapply in object List of type [a](List[a])Option[Null]
-and method unapply in object List of type [a](List[a])Option[(a, List[a])]
+both method unapply in object List of type [a](xs: List[a])Option[Null]
+and method unapply in object List of type [a](xs: List[a])Option[(a, List[a])]
match argument types (List[a])
case List(x, xs) => 7
^
diff --git a/test/files/neg/implicits.check b/test/files/neg/implicits.check
index b84586fc16..281f7a6dd2 100644
--- a/test/files/neg/implicits.check
+++ b/test/files/neg/implicits.check
@@ -2,8 +2,8 @@ implicits.scala:21: error: type mismatch;
found : Pos
required: ?{val +: ?}
Note that implicit conversions are not applicable because they are ambiguous:
- both method any2plus in object Sub of type (Any)Sub.Plus
- and method pos2int in object Super of type (Pos)int
+ both method any2plus in object Sub of type (x: Any)Sub.Plus
+ and method pos2int in object Super of type (p: Pos)int
are possible conversion functions from Pos to ?{val +: ?}
f(p+1)
^
diff --git a/test/files/neg/names-defaults-neg.check b/test/files/neg/names-defaults-neg.check
new file mode 100644
index 0000000000..5e621c9690
--- /dev/null
+++ b/test/files/neg/names-defaults-neg.check
@@ -0,0 +1,108 @@
+names-defaults-neg.scala:63: error: not enough arguments for method apply: (a: Int,b: String)(c: Int*)Fact in object Fact, unspecified parameter: value b
+ val fac = Fact(1)(2, 3)
+ ^
+names-defaults-neg.scala:5: error: type mismatch;
+ found : java.lang.String("#")
+ required: Int
+ test1(b = 2, a = "#")
+ ^
+names-defaults-neg.scala:8: error: positional after named argument.
+ test1(a = 1, "*")
+ ^
+names-defaults-neg.scala:9: error: positional after named argument.
+ test1(b = "(*", 23)
+ ^
+names-defaults-neg.scala:16: error: not found: value c
+ test1(c = 0, b = "joke")
+ ^
+names-defaults-neg.scala:20: error: parameter specified twice: a
+ test1(1, a = 2)
+ ^
+names-defaults-neg.scala:21: error: parameter specified twice: b
+ test1(b = 1, b = "2")
+ ^
+names-defaults-neg.scala:24: 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:33: 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:40: 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:41: 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:47: 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:51: error: parameter specified twice: b
+ test5(a = 1, b = "dkjl", b = "dkj")
+ ^
+names-defaults-neg.scala:52: error: parameter specified twice: b
+ test5(1, "2", b = 3)
+ ^
+names-defaults-neg.scala:53: error: when using named arguments, the vararg parameter has to be specified exactly once
+ test5(b = "dlkj")
+ ^
+names-defaults-neg.scala:59: 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:75: error: multiple overloaded alternatives of method foo define default arguments
+ def foo(a: Int = 0) = a
+ ^
+names-defaults-neg.scala:76: error: multiple overloaded alternatives of method foo define default arguments
+ def foo(b: String = "another") = b
+ ^
+names-defaults-neg.scala:76: error: method foo$default$1 is defined twice
+ def foo(b: String = "another") = b
+ ^
+names-defaults-neg.scala:85: error: multiple overloaded alternatives of method foo define default arguments
+ override def foo(a: Int = 1092) = a
+ ^
+names-defaults-neg.scala:86: error: multiple overloaded alternatives of method foo define default arguments
+ def foo(b: String = "lskdfj")
+ ^
+names-defaults-neg.scala:88: error: multiple overloaded alternatives of method bar define default arguments
+ def bar(i: Int = 129083) = i
+ ^
+names-defaults-neg.scala:88: error: type mismatch;
+ found : Int(129083)
+ required: java.lang.String
+ def bar(i: Int = 129083) = i
+ ^
+names-defaults-neg.scala:86: error: method foo$default$1 is defined twice
+ def foo(b: String = "lskdfj")
+ ^
+names-defaults-neg.scala:93: error: using named or default arguments in a super constructor call is not allowed
+class B1 extends A1(10)
+ ^
+names-defaults-neg.scala:94: error: using named or default arguments in a super constructor call is not allowed
+class B2 extends A1(y = 20, x = 2)
+ ^
+names-defaults-neg.scala:99: error: using named or default arguments in a self constructor call is not allowed
+ this(y = 10, x = a.toString())
+ ^
+names-defaults-neg.scala:105: error: using named or default arguments in a self constructor call is not allowed
+ this(sep + b + sep)
+ ^
+28 errors found
diff --git a/test/files/neg/names-defaults-neg.scala b/test/files/neg/names-defaults-neg.scala
new file mode 100644
index 0000000000..26663fe60d
--- /dev/null
+++ b/test/files/neg/names-defaults-neg.scala
@@ -0,0 +1,109 @@
+object Test extends Application {
+ // TESTS
+
+ // re-ordering
+ test1(b = 2, a = "#")
+
+ // mixing named and positional
+ test1(a = 1, "*")
+ test1(b = "(*", 23)
+
+ // assignment / names
+ var x = 0
+ var y = 0
+ test2(x = 1)
+ test2(y = 1)
+ test1(c = 0, b = "joke")
+
+
+ // argument specified twice
+ test1(1, a = 2)
+ test1(b = 1, b = "2")
+
+ // error message when there are too many argument lists (not very nice..)
+ test3(b = 3, a = 1)(3)
+
+
+
+ // overloading resolution
+ object t1 {
+ def f(a: Int, b: String) = "first"
+ def f(b: String, a: Int) = "second"
+ }
+ t1.f(b = "dkljf", a = 1)
+
+
+ object t3 {
+ def f(a1: Int) = "first"
+ def f(a2: Int)(b: Int) = "second"
+ }
+ t3.f(1)
+ t3.f(1)(2)
+
+ object t7 {
+ def g(a: C, b: Int*) = "third"
+ def g(a: B) = "fourth"
+ }
+ t7.g(new C()) // ambigous reference
+
+ // vararg
+ def test5(a: Int, b: String*) = a
+ test5(a = 1, b = "dkjl", b = "dkj")
+ test5(1, "2", b = 3)
+ test5(b = "dlkj")
+
+ object t8 {
+ def f(a: Int, b: Object) = "first"
+ def f(b: String, a: Int) = "second"
+ }
+ println(t8.f(a = 0, b = "1")) // ambigous reference
+
+
+ // case class copy does not exist if there's a vararg
+ val fac = Fact(1)(2, 3)
+ val facc = fac.copy(b = "dlkfj")()
+
+
+ // DEFINITIONS
+ def test1(a: Int, b: String) = a +": "+ b
+ def test2(x: Unit) = println("test2")
+ def test3(a: Int, b: Int) = a + b
+}
+
+// only one overloaded alternative is allowed to have defaults
+class A {
+ def foo(a: Int = 0) = a
+ def foo(b: String = "another") = b
+}
+
+class B {
+ def foo(a: Int) = a
+ def bar(u: String = "ldksj") = u
+}
+
+class C extends B {
+ override def foo(a: Int = 1092) = a
+ def foo(b: String = "lskdfj")
+
+ def bar(i: Int = 129083) = i
+}
+
+// using names / defaults in super constructor call not allowed
+class A1(x: Int, y: Int = 2)
+class B1 extends A1(10)
+class B2 extends A1(y = 20, x = 2)
+
+// using names / defaults in self constructor call not allowed
+class A2(x: String, y: Int = 10) {
+ def this(a: Object) {
+ this(y = 10, x = a.toString())
+ println(x)
+ }
+}
+class A3(x: String, y: Int = 11) {
+ def this(b: Double, sep: String) {
+ this(sep + b + sep)
+ }
+}
+
+case class Fact(a: Int, b: String)(c: Int*)
diff --git a/test/files/neg/overload.check b/test/files/neg/overload.check
index 760702778b..0faa97adb1 100644
--- a/test/files/neg/overload.check
+++ b/test/files/neg/overload.check
@@ -1,6 +1,6 @@
overload.scala:10: error: ambiguous reference to overloaded definition,
-both method f in class D of type (Any)Unit
-and method f in class C of type (int)Unit
+both method f in class D of type (x: Any)Unit
+and method f in class C of type (x: int)Unit
match argument types (Int)
(new D).f(1)
^
diff --git a/test/files/neg/t0259.check b/test/files/neg/t0259.check
index b0ab856278..a0b322d985 100644
--- a/test/files/neg/t0259.check
+++ b/test/files/neg/t0259.check
@@ -1,7 +1,7 @@
t0259.scala:4: error: double definition:
-constructor TestCase3:(String*)test.TestCase3 and
-constructor TestCase3:((String, Int)*)test.TestCase3 at line 3
-have same type after erasure: (Sequence)test.TestCase3
+constructor TestCase3:(groups: String*)test.TestCase3 and
+constructor TestCase3:(groups: (String, Int)*)test.TestCase3 at line 3
+have same type after erasure: (groups: Sequence)test.TestCase3
def this( groups: String*) = this()
^
one error found
diff --git a/test/files/neg/t0345.check b/test/files/neg/t0345.check
index f4a5275336..cf1d330360 100644
--- a/test/files/neg/t0345.check
+++ b/test/files/neg/t0345.check
@@ -1,4 +1,4 @@
-t0345.scala:2: error: object creation impossible, since method cons in trait Lizt of type (Nothing)Unit is not defined
+t0345.scala:2: error: object creation impossible, since method cons in trait Lizt of type (a: Nothing)Unit is not defined
val empty = new Lizt[Nothing] {
^
one error found
diff --git a/test/files/neg/t1659.check b/test/files/neg/t1659.check
deleted file mode 100644
index b4b3e8605e..0000000000
--- a/test/files/neg/t1659.check
+++ /dev/null
@@ -1,5 +0,0 @@
-t1659.scala:3: error: overriding method u in trait W of type [A](Y{type X = A})Unit;
- method u has incompatible type
-class Z extends W { def u[A](v : Y { type X = A }) = null }
- ^
-one error found
diff --git a/test/files/neg/t1659.scala b/test/files/neg/t1659.scala
deleted file mode 100644
index 10470d66f8..0000000000
--- a/test/files/neg/t1659.scala
+++ /dev/null
@@ -1,4 +0,0 @@
-trait Y { type X }
-trait W { def u[A](v : Y { type X = A }) : Unit }
-class Z extends W { def u[A](v : Y { type X = A }) = null }
-
diff --git a/test/files/neg/viewtest.check b/test/files/neg/viewtest.check
index 5415ba4f92..a93f803fe2 100644
--- a/test/files/neg/viewtest.check
+++ b/test/files/neg/viewtest.check
@@ -4,8 +4,8 @@ viewtest.scala:43: error: type mismatch;
case y1: List[a] => compareLists(x, y1)
^
viewtest.scala:104: error: ambiguous implicit values:
- both method view4 in object O of type [a](a)a
- and method identity in object Predef of type [A](A)A
+ both method view4 in object O of type [a](x: a)a
+ and method identity in object Predef of type [A](x: A)A
match expected type (test.Str) => test.Ordered[test.Str]
t = t insert Str(s)
^