summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2010-05-12 21:17:29 +0000
committerPaul Phillips <paulp@improving.org>2010-05-12 21:17:29 +0000
commit016d815104b1d44b2b899c68804dde500963fbcd (patch)
treee223ac275ad0321f9e5d51e847f30ab11e7a234f /test
parent0ed53d4d686db74a54315cd5ccf79bda3690b036 (diff)
downloadscala-016d815104b1d44b2b899c68804dde500963fbcd.tar.gz
scala-016d815104b1d44b2b899c68804dde500963fbcd.tar.bz2
scala-016d815104b1d44b2b899c68804dde500963fbcd.zip
Overhauled sequence length logic in the pattern...
Overhauled sequence length logic in the pattern matcher. Removes unnecessary boxing and a few varieties of wrongness. Closes #3395, #3150, #2958, #2945, #2187. No review.
Diffstat (limited to 'test')
-rw-r--r--test/files/pos/bug2187-2.scala7
-rw-r--r--test/files/pos/bug2945.scala12
-rw-r--r--test/files/run/bug2958.scala16
-rw-r--r--test/files/run/bug3150.scala10
-rw-r--r--test/files/run/bug3395.check2
-rw-r--r--test/files/run/bug3395.scala13
-rw-r--r--test/files/run/patmat-seqs.check13
-rw-r--r--test/files/run/patmat-seqs.scala42
8 files changed, 115 insertions, 0 deletions
diff --git a/test/files/pos/bug2187-2.scala b/test/files/pos/bug2187-2.scala
new file mode 100644
index 0000000000..3f2742dd89
--- /dev/null
+++ b/test/files/pos/bug2187-2.scala
@@ -0,0 +1,7 @@
+class Test {
+ def test[A](list: List[A]) = list match {
+ case Seq(x, y) => "xy"
+ case Seq(x) => "x"
+ case _ => "something else"
+ }
+} \ No newline at end of file
diff --git a/test/files/pos/bug2945.scala b/test/files/pos/bug2945.scala
new file mode 100644
index 0000000000..762bdb61e1
--- /dev/null
+++ b/test/files/pos/bug2945.scala
@@ -0,0 +1,12 @@
+object Foo {
+ def test(s: String) = {
+ (s: Seq[Char]) match {
+ case Seq('f', 'o', 'o', ' ', rest1 @ _*) =>
+ rest1
+ case Seq('b', 'a', 'r', ' ', ' ', rest2 @ _*) =>
+ rest2
+ case _ =>
+ s
+ }
+ }
+} \ No newline at end of file
diff --git a/test/files/run/bug2958.scala b/test/files/run/bug2958.scala
new file mode 100644
index 0000000000..dcd24ecc36
--- /dev/null
+++ b/test/files/run/bug2958.scala
@@ -0,0 +1,16 @@
+object Test {
+ def f(args: Array[String]) = args match {
+ case Array("-p", prefix, from, to) =>
+ prefix + from + to
+
+ case Array(from, to) =>
+ from + to
+
+ case _ =>
+ "default"
+ }
+
+ def main(args: Array[String]) {
+ assert(f(Array("1", "2")) == "12")
+ }
+} \ No newline at end of file
diff --git a/test/files/run/bug3150.scala b/test/files/run/bug3150.scala
new file mode 100644
index 0000000000..034703b5f7
--- /dev/null
+++ b/test/files/run/bug3150.scala
@@ -0,0 +1,10 @@
+object Test {
+ case object Bob { override def equals(other: Any) = true }
+ def f(x: Any) = x match { case Bob => Bob }
+
+ def main(args: Array[String]): Unit = {
+ assert(f(Bob) eq Bob)
+ assert(f(0) eq Bob)
+ assert(f(Nil) eq Bob)
+ }
+}
diff --git a/test/files/run/bug3395.check b/test/files/run/bug3395.check
new file mode 100644
index 0000000000..5f5521fae2
--- /dev/null
+++ b/test/files/run/bug3395.check
@@ -0,0 +1,2 @@
+abc
+def
diff --git a/test/files/run/bug3395.scala b/test/files/run/bug3395.scala
new file mode 100644
index 0000000000..b4990a1716
--- /dev/null
+++ b/test/files/run/bug3395.scala
@@ -0,0 +1,13 @@
+object Test {
+ def main(args: Array[String]): Unit = {
+ Seq("") match {
+ case Seq("") => println("abc")
+ case Seq(_, _, x) => println(x)
+ }
+
+ Seq(1, 2, "def") match {
+ case Seq("") => println("abc")
+ case Seq(_, _, x) => println(x)
+ }
+ }
+} \ No newline at end of file
diff --git a/test/files/run/patmat-seqs.check b/test/files/run/patmat-seqs.check
new file mode 100644
index 0000000000..bb2a5ee44a
--- /dev/null
+++ b/test/files/run/patmat-seqs.check
@@ -0,0 +1,13 @@
+s3
+s2
+s1
+s0
+ss6
+d
+s3
+s3
+d
+s1
+s3
+d
+d
diff --git a/test/files/run/patmat-seqs.scala b/test/files/run/patmat-seqs.scala
new file mode 100644
index 0000000000..b5c47b4b4b
--- /dev/null
+++ b/test/files/run/patmat-seqs.scala
@@ -0,0 +1,42 @@
+object Test {
+ def f1(x: Any) = x match {
+ case Seq(1, 2, 3) => "s3"
+ case Seq(4, 5) => "s2"
+ case Seq(7) => "s1"
+ case Nil => "s0"
+ case Seq(_, _, _, _, _, x: String) => "ss6"
+ case _ => "d"
+ }
+
+ def f2(x: Any) = x match {
+ case Seq("a", "b", _*) => "s2"
+ case Seq(1, _*) => "s1"
+ case Seq(5, 6, 7, _*) => "s3"
+ case _ => "d"
+ }
+
+ def main(args: Array[String]): Unit = {
+ val xs1 = List(
+ List(1,2,3),
+ List(4,5),
+ Vector(7),
+ Seq(),
+ Seq(1, 2, 3, 4, 5, "abcd"),
+ "abc"
+ ) map f1
+
+ xs1 foreach println
+
+ val xs2 = List(
+ Seq(5, 6, 7),
+ Seq(5, 6, 7, 8, 9),
+ Seq("a"),
+ Seq(1, 6, 7),
+ List(5, 6, 7),
+ Nil,
+ 5
+ ) map f2
+
+ xs2 foreach println
+ }
+}