summaryrefslogtreecommitdiff
path: root/test/files/run/virtpatmat_unapply.scala
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/virtpatmat_unapply.scala
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/virtpatmat_unapply.scala')
-rw-r--r--test/files/run/virtpatmat_unapply.scala32
1 files changed, 32 insertions, 0 deletions
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