summaryrefslogtreecommitdiff
path: root/test/files/run
diff options
context:
space:
mode:
authorAdriaan Moors <adriaan.moors@epfl.ch>2011-10-20 22:29:20 +0000
committerAdriaan Moors <adriaan.moors@epfl.ch>2011-10-20 22:29:20 +0000
commit8a9fd64129926eea35f7dca181242855f14e153f (patch)
tree4defd18749999b6e14d9fba1ccc5e1507b453a64 /test/files/run
parent891a6e466b1b22b93c091d590178f7e5410f608e (diff)
downloadscala-8a9fd64129926eea35f7dca181242855f14e153f.tar.gz
scala-8a9fd64129926eea35f7dca181242855f14e153f.tar.bz2
scala-8a9fd64129926eea35f7dca181242855f14e153f.zip
virtpatmat, hidden behind -Yvirtpatmat
at least one imminent TODO: undo hardwired generation of if/then/else, and decide based on type whether to call flatMap/orElse or inline those methods from Option review by extempore
Diffstat (limited to 'test/files/run')
-rw-r--r--test/files/run/virtpatmat_alts.check1
-rw-r--r--test/files/run/virtpatmat_alts.flags1
-rw-r--r--test/files/run/virtpatmat_alts.scala12
-rw-r--r--test/files/run/virtpatmat_apply.check1
-rw-r--r--test/files/run/virtpatmat_apply.flags1
-rw-r--r--test/files/run/virtpatmat_apply.scala7
-rw-r--r--test/files/run/virtpatmat_casting.check1
-rw-r--r--test/files/run/virtpatmat_casting.flags1
-rw-r--r--test/files/run/virtpatmat_casting.scala8
-rw-r--r--test/files/run/virtpatmat_literal.check3
-rw-r--r--test/files/run/virtpatmat_literal.flags1
-rw-r--r--test/files/run/virtpatmat_literal.scala21
-rw-r--r--test/files/run/virtpatmat_nested_lists.check1
-rw-r--r--test/files/run/virtpatmat_nested_lists.flags1
-rw-r--r--test/files/run/virtpatmat_nested_lists.scala3
-rw-r--r--test/files/run/virtpatmat_npe.check1
-rw-r--r--test/files/run/virtpatmat_npe.flags1
-rw-r--r--test/files/run/virtpatmat_npe.scala10
-rw-r--r--test/files/run/virtpatmat_partial.check2
-rw-r--r--test/files/run/virtpatmat_partial.flags1
-rw-r--r--test/files/run/virtpatmat_partial.scala73
-rw-r--r--test/files/run/virtpatmat_typed.check1
-rw-r--r--test/files/run/virtpatmat_typed.flags1
-rw-r--r--test/files/run/virtpatmat_typed.scala7
-rw-r--r--test/files/run/virtpatmat_unapply.check2
-rw-r--r--test/files/run/virtpatmat_unapply.flags1
-rw-r--r--test/files/run/virtpatmat_unapply.scala32
-rw-r--r--test/files/run/virtpatmat_unapplyseq.check1
-rw-r--r--test/files/run/virtpatmat_unapplyseq.flags1
-rw-r--r--test/files/run/virtpatmat_unapplyseq.scala5
30 files changed, 202 insertions, 0 deletions
diff --git a/test/files/run/virtpatmat_alts.check b/test/files/run/virtpatmat_alts.check
new file mode 100644
index 0000000000..7a4ad0a741
--- /dev/null
+++ b/test/files/run/virtpatmat_alts.check
@@ -0,0 +1 @@
+OK 5
diff --git a/test/files/run/virtpatmat_alts.flags b/test/files/run/virtpatmat_alts.flags
new file mode 100644
index 0000000000..9769db9257
--- /dev/null
+++ b/test/files/run/virtpatmat_alts.flags
@@ -0,0 +1 @@
+ -Yvirtpatmat -Xexperimental
diff --git a/test/files/run/virtpatmat_alts.scala b/test/files/run/virtpatmat_alts.scala
new file mode 100644
index 0000000000..b7717524e2
--- /dev/null
+++ b/test/files/run/virtpatmat_alts.scala
@@ -0,0 +1,12 @@
+object Test extends App {
+ (true, true) match {
+ case (true, true) | (false, false) => 1
+ }
+
+ List(5) match {
+ case 1 :: Nil | 2 :: Nil => println("FAILED")
+ case (x@(4 | 5 | 6)) :: Nil => println("OK "+ x)
+ case 7 :: Nil => println("FAILED")
+ case Nil => println("FAILED")
+ }
+} \ No newline at end of file
diff --git a/test/files/run/virtpatmat_apply.check b/test/files/run/virtpatmat_apply.check
new file mode 100644
index 0000000000..e8e3b295e6
--- /dev/null
+++ b/test/files/run/virtpatmat_apply.check
@@ -0,0 +1 @@
+OK 2
diff --git a/test/files/run/virtpatmat_apply.flags b/test/files/run/virtpatmat_apply.flags
new file mode 100644
index 0000000000..9769db9257
--- /dev/null
+++ b/test/files/run/virtpatmat_apply.flags
@@ -0,0 +1 @@
+ -Yvirtpatmat -Xexperimental
diff --git a/test/files/run/virtpatmat_apply.scala b/test/files/run/virtpatmat_apply.scala
new file mode 100644
index 0000000000..b8776f4afb
--- /dev/null
+++ b/test/files/run/virtpatmat_apply.scala
@@ -0,0 +1,7 @@
+object Test extends App {
+ List(1, 2, 3) match {
+ case Nil => println("FAIL")
+ case x :: y :: xs if xs.length == 2 => println("FAIL")
+ case x :: y :: xs if xs.length == 1 => println("OK "+ y)
+ }
+} \ No newline at end of file
diff --git a/test/files/run/virtpatmat_casting.check b/test/files/run/virtpatmat_casting.check
new file mode 100644
index 0000000000..b11425edc8
--- /dev/null
+++ b/test/files/run/virtpatmat_casting.check
@@ -0,0 +1 @@
+List(1)
diff --git a/test/files/run/virtpatmat_casting.flags b/test/files/run/virtpatmat_casting.flags
new file mode 100644
index 0000000000..9769db9257
--- /dev/null
+++ b/test/files/run/virtpatmat_casting.flags
@@ -0,0 +1 @@
+ -Yvirtpatmat -Xexperimental
diff --git a/test/files/run/virtpatmat_casting.scala b/test/files/run/virtpatmat_casting.scala
new file mode 100644
index 0000000000..7c5e1c7117
--- /dev/null
+++ b/test/files/run/virtpatmat_casting.scala
@@ -0,0 +1,8 @@
+object Test extends App {
+ println(List(1,2,3) match {
+ case Nil => List(0)
+// since the :: extractor's argument must be a ::, there has to be a cast before its unapply is invoked
+ case x :: y :: z :: a :: xs => xs ++ List(x)
+ case x :: y :: z :: xs => xs ++ List(x)
+ })
+}
diff --git a/test/files/run/virtpatmat_literal.check b/test/files/run/virtpatmat_literal.check
new file mode 100644
index 0000000000..0eabe36713
--- /dev/null
+++ b/test/files/run/virtpatmat_literal.check
@@ -0,0 +1,3 @@
+OK
+OK
+OK
diff --git a/test/files/run/virtpatmat_literal.flags b/test/files/run/virtpatmat_literal.flags
new file mode 100644
index 0000000000..9769db9257
--- /dev/null
+++ b/test/files/run/virtpatmat_literal.flags
@@ -0,0 +1 @@
+ -Yvirtpatmat -Xexperimental
diff --git a/test/files/run/virtpatmat_literal.scala b/test/files/run/virtpatmat_literal.scala
new file mode 100644
index 0000000000..460811eba9
--- /dev/null
+++ b/test/files/run/virtpatmat_literal.scala
@@ -0,0 +1,21 @@
+object Test extends App {
+ 1 match {
+ case 2 => println("FAILED")
+ case 1 => println("OK")
+ case 1 => println("FAILED")
+ }
+
+ val one = 1
+ 1 match {
+ case 2 => println("FAILED")
+ case `one` => println("OK")
+ case 1 => println("FAILED")
+ }
+
+ 1 match {
+ case 2 => println("FAILED")
+ case Test.one => println("OK")
+ case 1 => println("FAILED")
+ }
+
+} \ No newline at end of file
diff --git a/test/files/run/virtpatmat_nested_lists.check b/test/files/run/virtpatmat_nested_lists.check
new file mode 100644
index 0000000000..d8263ee986
--- /dev/null
+++ b/test/files/run/virtpatmat_nested_lists.check
@@ -0,0 +1 @@
+2 \ No newline at end of file
diff --git a/test/files/run/virtpatmat_nested_lists.flags b/test/files/run/virtpatmat_nested_lists.flags
new file mode 100644
index 0000000000..9769db9257
--- /dev/null
+++ b/test/files/run/virtpatmat_nested_lists.flags
@@ -0,0 +1 @@
+ -Yvirtpatmat -Xexperimental
diff --git a/test/files/run/virtpatmat_nested_lists.scala b/test/files/run/virtpatmat_nested_lists.scala
new file mode 100644
index 0000000000..fef74cea15
--- /dev/null
+++ b/test/files/run/virtpatmat_nested_lists.scala
@@ -0,0 +1,3 @@
+object Test extends App {
+ List(List(1), List(2)) match { case x :: (y :: Nil) :: Nil => println(y) }
+}
diff --git a/test/files/run/virtpatmat_npe.check b/test/files/run/virtpatmat_npe.check
new file mode 100644
index 0000000000..a0aba9318a
--- /dev/null
+++ b/test/files/run/virtpatmat_npe.check
@@ -0,0 +1 @@
+OK \ No newline at end of file
diff --git a/test/files/run/virtpatmat_npe.flags b/test/files/run/virtpatmat_npe.flags
new file mode 100644
index 0000000000..9769db9257
--- /dev/null
+++ b/test/files/run/virtpatmat_npe.flags
@@ -0,0 +1 @@
+ -Yvirtpatmat -Xexperimental
diff --git a/test/files/run/virtpatmat_npe.scala b/test/files/run/virtpatmat_npe.scala
new file mode 100644
index 0000000000..84a9276454
--- /dev/null
+++ b/test/files/run/virtpatmat_npe.scala
@@ -0,0 +1,10 @@
+class C {
+ class D
+ val values = new Array[AnyRef](10)
+ values(0) match {
+ case name: D => println("NOK: "+ name) // the outer check on D's outer should not cause a NPE
+ case null => println("OK")
+ }
+}
+
+object Test extends C with App \ No newline at end of file
diff --git a/test/files/run/virtpatmat_partial.check b/test/files/run/virtpatmat_partial.check
new file mode 100644
index 0000000000..093020ce05
--- /dev/null
+++ b/test/files/run/virtpatmat_partial.check
@@ -0,0 +1,2 @@
+Map(a -> Some(1), b -> None)
+Map(a -> 1) \ No newline at end of file
diff --git a/test/files/run/virtpatmat_partial.flags b/test/files/run/virtpatmat_partial.flags
new file mode 100644
index 0000000000..9769db9257
--- /dev/null
+++ b/test/files/run/virtpatmat_partial.flags
@@ -0,0 +1 @@
+ -Yvirtpatmat -Xexperimental
diff --git a/test/files/run/virtpatmat_partial.scala b/test/files/run/virtpatmat_partial.scala
new file mode 100644
index 0000000000..d30944efb4
--- /dev/null
+++ b/test/files/run/virtpatmat_partial.scala
@@ -0,0 +1,73 @@
+object Test extends App {
+ val a = Map("a" -> Some(1), "b" -> None)
+ println(a)
+
+ val res = a collect {case (p, Some(a)) => (p, a)}
+
+ // should uncurry to:
+ // val res: Map[String,Int] = a.collect[(String, Int), Map[String,Int]](
+ // new PartialFunction[(String, Option[Int]),(String, Int)] {
+ // def apply(x0_1: (String, Option[Int])): (String, Int) = MatchingStrategy.OptionMatchingStrategy.runOrElse[(String, Option[Int]), (String, Int)](x0_1)(
+ // (x1: (String, Option[Int])) => {
+ // val o9: Option[(String, Int)] = ({
+ // val o8: Option[(String, Option[Int])] = Tuple2.unapply[String, Option[Int]](x1);
+ // if (o8.isEmpty)
+ // MatchingStrategy.OptionMatchingStrategy.zero
+ // else
+ // {
+ // val o7: Option[Some[Int]] = if (o8.get._2.isInstanceOf[Some[Int]])
+ // MatchingStrategy.OptionMatchingStrategy.one[Some[Int]](o8.get._2.asInstanceOf[Some[Int]])
+ // else
+ // MatchingStrategy.OptionMatchingStrategy.zero;
+ // if (o7.isEmpty)
+ // MatchingStrategy.OptionMatchingStrategy.zero
+ // else
+ // {
+ // val o6: Option[Int] = Some.unapply[Int](o7.get);
+ // if (o6.isEmpty)
+ // MatchingStrategy.OptionMatchingStrategy.zero
+ // else
+ // MatchingStrategy.OptionMatchingStrategy.one[(String, Int)]((o8.get._1, o6.get).asInstanceOf[(String, Int)])
+ // }
+ // }
+ // }: Option[(String, Int)]);
+ // if (o9.isEmpty)
+ // (MatchingStrategy.OptionMatchingStrategy.zero: Option[(String, Int)])
+ // else
+ // o9
+ // })
+ //
+ // def isDefinedAt(x_1: (String, Option[Int])): Boolean = MatchingStrategy.OptionMatchingStrategy.isSuccess[(String, Option[Int]), (String, Int)](x_1)(
+ // (x1: (String, Option[Int])) => {
+ // val o9: Option[(String, Int)] = ({
+ // val o8: Option[(String, Option[Int])] = scala.Tuple2.unapply[String, Option[Int]](x1);
+ // if (o8.isEmpty)
+ // MatchingStrategy.OptionMatchingStrategy.zero
+ // else
+ // {
+ // val o7: Option[Some[Int]] = if (o8.get._2.isInstanceOf[Some[Int]])
+ // MatchingStrategy.OptionMatchingStrategy.one[Some[Int]](o8.get._2.asInstanceOf[Some[Int]]) // XXX
+ // else
+ // MatchingStrategy.OptionMatchingStrategy.zero;
+ // if (o7.isEmpty)
+ // MatchingStrategy.OptionMatchingStrategy.zero
+ // else
+ // {
+ // val o6: Option[Int] = scala.Some.unapply[Int](o7.get);
+ // if (o6.isEmpty)
+ // MatchingStrategy.OptionMatchingStrategy.zero
+ // else
+ // MatchingStrategy.OptionMatchingStrategy.one[(String, Int)](null.asInstanceOf[(String, Int)])
+ // }
+ // }
+ // }: Option[(String, Int)]);
+ // if (o9.isEmpty)
+ // (MatchingStrategy.OptionMatchingStrategy.zero: Option[(String, Int)])
+ // else
+ // o9
+ // })
+ // }
+ // )
+
+ println(res)
+}
diff --git a/test/files/run/virtpatmat_typed.check b/test/files/run/virtpatmat_typed.check
new file mode 100644
index 0000000000..cec2740d18
--- /dev/null
+++ b/test/files/run/virtpatmat_typed.check
@@ -0,0 +1 @@
+OK foo
diff --git a/test/files/run/virtpatmat_typed.flags b/test/files/run/virtpatmat_typed.flags
new file mode 100644
index 0000000000..9769db9257
--- /dev/null
+++ b/test/files/run/virtpatmat_typed.flags
@@ -0,0 +1 @@
+ -Yvirtpatmat -Xexperimental
diff --git a/test/files/run/virtpatmat_typed.scala b/test/files/run/virtpatmat_typed.scala
new file mode 100644
index 0000000000..cdd6d3c749
--- /dev/null
+++ b/test/files/run/virtpatmat_typed.scala
@@ -0,0 +1,7 @@
+object Test extends App {
+ ("foo": Any) match {
+ case x: Int => println("FAILED")
+ case x: String => println("OK "+ x)
+ case x: String => println("FAILED")
+ }
+} \ No newline at end of file
diff --git a/test/files/run/virtpatmat_unapply.check b/test/files/run/virtpatmat_unapply.check
new file mode 100644
index 0000000000..2b89b77d1e
--- /dev/null
+++ b/test/files/run/virtpatmat_unapply.check
@@ -0,0 +1,2 @@
+1
+6
diff --git a/test/files/run/virtpatmat_unapply.flags b/test/files/run/virtpatmat_unapply.flags
new file mode 100644
index 0000000000..9769db9257
--- /dev/null
+++ b/test/files/run/virtpatmat_unapply.flags
@@ -0,0 +1 @@
+ -Yvirtpatmat -Xexperimental
diff --git a/test/files/run/virtpatmat_unapply.scala b/test/files/run/virtpatmat_unapply.scala
new file mode 100644
index 0000000000..a6e71f3963
--- /dev/null
+++ b/test/files/run/virtpatmat_unapply.scala
@@ -0,0 +1,32 @@
+class IntList(val hd: Int, val tl: IntList)
+object NilIL extends IntList(0, null)
+object IntList {
+ def unapply(il: IntList): Option[(Int, IntList)] = if(il eq NilIL) None else Some(il.hd, il.tl)
+ def apply(x: Int, xs: IntList) = new IntList(x, xs)
+}
+
+object Test extends App {
+ IntList(1, IntList(2, NilIL)) match {
+ case IntList(a1, IntList(a2, IntList(a3, y))) => println(a1 + a2 + a3)
+ case IntList(x, y) => println(x)
+ }
+
+ IntList(1, IntList(2, IntList(3, NilIL))) match {
+ case IntList(a1, IntList(a2, IntList(a3, y))) => println(a1 + a2 + a3)
+ case IntList(x, y) => println(x)
+ }
+}
+
+// ((x1: IntList) => IntList.unapply(x1).flatMap(((x4: (Int, IntList)) => IntList.unapply(x4._2).flatMap(((x5: (Int, IntList)) => IntList.unapply(x5._2).flatMap(((x6: (Int, IntList)) => implicitly[Predef.MatchingStrategy[Option]].success(Predef.println(x4._1.+(x5._1).+(x6._1))))))))).orElse(IntList.unapply(x1).flatMap(((x7: (Int, IntList)) => implicitly[scala.Predef.MatchingStrategy[Option]].success(Predef.println(x7._1))))).orElse(implicitly[scala.Predef.MatchingStrategy[Option]].fail))(IntList.apply(1, IntList.apply(2, IntList.apply(3, null))))
+
+/*
+ ((x1: IntList) =>
+ IntList.this.unapply(x1).flatMap[Int](((x4: (Int, IntList)) =>
+ IntList.this.unapply(x4._2).flatMap[Int](((x5: (Int, IntList)) =>
+ IntList.this.unapply(x5._2).flatMap[Int](((x6: (Int, IntList)) =>
+ Predef.this.implicitly[scala.Predef.MatchingStrategy[Option]](scala.this.Predef.OptionMatching).success[Int](x6._1))))))).orElse[Int](
+ IntList.this.unapply(x1).flatMap[Int](((x7: (Int, IntList)) =>
+ Predef.this.implicitly[scala.Predef.MatchingStrategy[Option]](scala.this.Predef.OptionMatching).success[Int](x7._1)))).orElse[Int](
+ Predef.this.implicitly[scala.Predef.MatchingStrategy[Option]](scala.this.Predef.OptionMatching).fail)
+ ).apply(IntList.apply(1, null))
+*/ \ No newline at end of file
diff --git a/test/files/run/virtpatmat_unapplyseq.check b/test/files/run/virtpatmat_unapplyseq.check
new file mode 100644
index 0000000000..62f9457511
--- /dev/null
+++ b/test/files/run/virtpatmat_unapplyseq.check
@@ -0,0 +1 @@
+6 \ No newline at end of file
diff --git a/test/files/run/virtpatmat_unapplyseq.flags b/test/files/run/virtpatmat_unapplyseq.flags
new file mode 100644
index 0000000000..9769db9257
--- /dev/null
+++ b/test/files/run/virtpatmat_unapplyseq.flags
@@ -0,0 +1 @@
+ -Yvirtpatmat -Xexperimental
diff --git a/test/files/run/virtpatmat_unapplyseq.scala b/test/files/run/virtpatmat_unapplyseq.scala
new file mode 100644
index 0000000000..270fa9045a
--- /dev/null
+++ b/test/files/run/virtpatmat_unapplyseq.scala
@@ -0,0 +1,5 @@
+object Test extends App {
+ List(1,2,3) match {
+ case Seq(x, y, z) => println(x * y * z)
+ }
+} \ No newline at end of file