From 8a9fd64129926eea35f7dca181242855f14e153f Mon Sep 17 00:00:00 2001 From: Adriaan Moors Date: Thu, 20 Oct 2011 22:29:20 +0000 Subject: 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 --- test/files/pos/virtpatmat_castbinder.flags | 1 + test/files/pos/virtpatmat_castbinder.scala | 15 ++++++ test/files/pos/virtpatmat_exist1.flags | 1 + test/files/pos/virtpatmat_exist1.scala | 24 +++++++++ test/files/pos/virtpatmat_exist2.flags | 1 + test/files/pos/virtpatmat_exist2.scala | 20 +++++++ test/files/pos/virtpatmat_exist3.flags | 1 + test/files/pos/virtpatmat_exist3.scala | 12 +++++ test/files/pos/virtpatmat_gadt_array.flags | 1 + test/files/pos/virtpatmat_gadt_array.scala | 15 ++++++ test/files/pos/virtpatmat_infer_single_1.flags | 1 + test/files/pos/virtpatmat_infer_single_1.scala | 7 +++ test/files/pos/virtpatmat_obj_in_case.flags | 1 + test/files/pos/virtpatmat_obj_in_case.scala | 5 ++ test/files/run/virtpatmat_alts.check | 1 + test/files/run/virtpatmat_alts.flags | 1 + test/files/run/virtpatmat_alts.scala | 12 +++++ test/files/run/virtpatmat_apply.check | 1 + test/files/run/virtpatmat_apply.flags | 1 + test/files/run/virtpatmat_apply.scala | 7 +++ test/files/run/virtpatmat_casting.check | 1 + test/files/run/virtpatmat_casting.flags | 1 + test/files/run/virtpatmat_casting.scala | 8 +++ test/files/run/virtpatmat_literal.check | 3 ++ test/files/run/virtpatmat_literal.flags | 1 + test/files/run/virtpatmat_literal.scala | 21 ++++++++ test/files/run/virtpatmat_nested_lists.check | 1 + test/files/run/virtpatmat_nested_lists.flags | 1 + test/files/run/virtpatmat_nested_lists.scala | 3 ++ test/files/run/virtpatmat_npe.check | 1 + test/files/run/virtpatmat_npe.flags | 1 + test/files/run/virtpatmat_npe.scala | 10 ++++ test/files/run/virtpatmat_partial.check | 2 + test/files/run/virtpatmat_partial.flags | 1 + test/files/run/virtpatmat_partial.scala | 73 ++++++++++++++++++++++++++ test/files/run/virtpatmat_typed.check | 1 + test/files/run/virtpatmat_typed.flags | 1 + test/files/run/virtpatmat_typed.scala | 7 +++ test/files/run/virtpatmat_unapply.check | 2 + test/files/run/virtpatmat_unapply.flags | 1 + test/files/run/virtpatmat_unapply.scala | 32 +++++++++++ test/files/run/virtpatmat_unapplyseq.check | 1 + test/files/run/virtpatmat_unapplyseq.flags | 1 + test/files/run/virtpatmat_unapplyseq.scala | 5 ++ 44 files changed, 307 insertions(+) create mode 100644 test/files/pos/virtpatmat_castbinder.flags create mode 100644 test/files/pos/virtpatmat_castbinder.scala create mode 100644 test/files/pos/virtpatmat_exist1.flags create mode 100644 test/files/pos/virtpatmat_exist1.scala create mode 100644 test/files/pos/virtpatmat_exist2.flags create mode 100644 test/files/pos/virtpatmat_exist2.scala create mode 100644 test/files/pos/virtpatmat_exist3.flags create mode 100644 test/files/pos/virtpatmat_exist3.scala create mode 100644 test/files/pos/virtpatmat_gadt_array.flags create mode 100644 test/files/pos/virtpatmat_gadt_array.scala create mode 100644 test/files/pos/virtpatmat_infer_single_1.flags create mode 100644 test/files/pos/virtpatmat_infer_single_1.scala create mode 100644 test/files/pos/virtpatmat_obj_in_case.flags create mode 100644 test/files/pos/virtpatmat_obj_in_case.scala create mode 100644 test/files/run/virtpatmat_alts.check create mode 100644 test/files/run/virtpatmat_alts.flags create mode 100644 test/files/run/virtpatmat_alts.scala create mode 100644 test/files/run/virtpatmat_apply.check create mode 100644 test/files/run/virtpatmat_apply.flags create mode 100644 test/files/run/virtpatmat_apply.scala create mode 100644 test/files/run/virtpatmat_casting.check create mode 100644 test/files/run/virtpatmat_casting.flags create mode 100644 test/files/run/virtpatmat_casting.scala create mode 100644 test/files/run/virtpatmat_literal.check create mode 100644 test/files/run/virtpatmat_literal.flags create mode 100644 test/files/run/virtpatmat_literal.scala create mode 100644 test/files/run/virtpatmat_nested_lists.check create mode 100644 test/files/run/virtpatmat_nested_lists.flags create mode 100644 test/files/run/virtpatmat_nested_lists.scala create mode 100644 test/files/run/virtpatmat_npe.check create mode 100644 test/files/run/virtpatmat_npe.flags create mode 100644 test/files/run/virtpatmat_npe.scala create mode 100644 test/files/run/virtpatmat_partial.check create mode 100644 test/files/run/virtpatmat_partial.flags create mode 100644 test/files/run/virtpatmat_partial.scala create mode 100644 test/files/run/virtpatmat_typed.check create mode 100644 test/files/run/virtpatmat_typed.flags create mode 100644 test/files/run/virtpatmat_typed.scala create mode 100644 test/files/run/virtpatmat_unapply.check create mode 100644 test/files/run/virtpatmat_unapply.flags create mode 100644 test/files/run/virtpatmat_unapply.scala create mode 100644 test/files/run/virtpatmat_unapplyseq.check create mode 100644 test/files/run/virtpatmat_unapplyseq.flags create mode 100644 test/files/run/virtpatmat_unapplyseq.scala (limited to 'test') diff --git a/test/files/pos/virtpatmat_castbinder.flags b/test/files/pos/virtpatmat_castbinder.flags new file mode 100644 index 0000000000..9769db9257 --- /dev/null +++ b/test/files/pos/virtpatmat_castbinder.flags @@ -0,0 +1 @@ + -Yvirtpatmat -Xexperimental diff --git a/test/files/pos/virtpatmat_castbinder.scala b/test/files/pos/virtpatmat_castbinder.scala new file mode 100644 index 0000000000..be269638ce --- /dev/null +++ b/test/files/pos/virtpatmat_castbinder.scala @@ -0,0 +1,15 @@ +class IntMap[+V] +case class Bin[+T](m: IntMap[T]) extends IntMap[T] +case class Tip[+T](x: T) extends IntMap[T] + +trait IntMapIterator[V, T] { + def valueOf(tip: Tip[V]): T + def pop: IntMap[V] + + def next: T = + pop match { + case Bin(t@Tip(_)) => { + valueOf(t) + } + } +} \ No newline at end of file diff --git a/test/files/pos/virtpatmat_exist1.flags b/test/files/pos/virtpatmat_exist1.flags new file mode 100644 index 0000000000..9769db9257 --- /dev/null +++ b/test/files/pos/virtpatmat_exist1.flags @@ -0,0 +1 @@ + -Yvirtpatmat -Xexperimental diff --git a/test/files/pos/virtpatmat_exist1.scala b/test/files/pos/virtpatmat_exist1.scala new file mode 100644 index 0000000000..6cad017b0b --- /dev/null +++ b/test/files/pos/virtpatmat_exist1.scala @@ -0,0 +1,24 @@ +import annotation.unchecked.{ uncheckedVariance=> uV } +import scala.collection.immutable.{ListMap, HashMap, ListSet, HashSet} + +object Test { + class HashMapCollision1[A, +B](var hash: Int, var kvs: ListMap[A, B @uV]) extends HashMap[A, B @uV] + class HashSetCollision1[A](var hash: Int, var ks: ListSet[A]) extends HashSet[A] + + def splitArray[T](ad: Array[Iterable[T]]): Any = + ad(0) match { + case _: HashMapCollision1[_, _] | _: HashSetCollision1[_] => null + } + + // without type ascription for the one in the body of the last flatmap of each alternative, type inference borks on the existentials + // def splitArray[T >: Nothing <: Any](ad: Array[Iterable[T]]): Any = { import OptionMatching._ + // runOrElse(ad.apply(0))(((x1: Iterable[T]) => ( + // or(((x4: Iterable[T]) => one(null)), + // guard(x1.isInstanceOf[Iterable[T] with Test.HashMapCollision1[_,_]], x1.asInstanceOf[Iterable[T] with Test.HashMapCollision1[_,_]]).flatMap(((x2: Iterable[T] with Test.HashMapCollision1[_,_]) => one(x2))), + // guard(x1.isInstanceOf[Test.HashSetCollision1[_]], x1.asInstanceOf[Iterable[T] with Test.HashSetCollision1[_]]).flatMap(((x3: Iterable[T] with Test.HashSetCollision1[_]) => one(x3)))): Option[Any]).orElse( + // (zero: Option[Any]))) + // ) + // } + +} + diff --git a/test/files/pos/virtpatmat_exist2.flags b/test/files/pos/virtpatmat_exist2.flags new file mode 100644 index 0000000000..9769db9257 --- /dev/null +++ b/test/files/pos/virtpatmat_exist2.flags @@ -0,0 +1 @@ + -Yvirtpatmat -Xexperimental diff --git a/test/files/pos/virtpatmat_exist2.scala b/test/files/pos/virtpatmat_exist2.scala new file mode 100644 index 0000000000..ee186074ab --- /dev/null +++ b/test/files/pos/virtpatmat_exist2.scala @@ -0,0 +1,20 @@ +class ParseResult[+T] +case class MemoEntry[+T](var r: Either[Nothing,ParseResult[_]]) + +object Test { + def grow[T]: ParseResult[T] = (null: MemoEntry[T]) match { + case MemoEntry(Right(x: ParseResult[_])) => x.asInstanceOf[ParseResult[T]] + } + + // what's the _$1 doing there? + // def grow[T >: Nothing <: Any]: ParseResult[T] = { + // import OptionMatching._ + // runOrElse[MemoEntry[T], ParseResult[T]]((null: MemoEntry[T]))(((x1: MemoEntry[T]) => + // (MemoEntry.unapply[T](x1).flatMap[ParseResult[T]](((x4: Either[Nothing,ParseResult[_]]) => + // guard[Right[Nothing,ParseResult[_]]](x4.isInstanceOf[Right[Nothing,ParseResult[_]]], x4.asInstanceOf[Right[Nothing,ParseResult[_]]]).flatMap[ParseResult[T]](((cp3: Right[Nothing,ParseResult[_]]) => + // scala.Right.unapply[Nothing, ParseResult[_]](cp3).flatMap[ParseResult[T]](((x5: ParseResult[_]) => + // guard[ParseResult[_$1]](x5.ne(null), x5.asInstanceOf[ParseResult[_]]).flatMap[ParseResult[T]](((x6: ParseResult[_]) => + // one[ParseResult[T]](x6.asInstanceOf[ParseResult[T]]))))))))): Option[ParseResult[T]] + // ).orElse[ParseResult[T]]((zero: Option[ParseResult[T]])))) + // } +} \ No newline at end of file diff --git a/test/files/pos/virtpatmat_exist3.flags b/test/files/pos/virtpatmat_exist3.flags new file mode 100644 index 0000000000..9769db9257 --- /dev/null +++ b/test/files/pos/virtpatmat_exist3.flags @@ -0,0 +1 @@ + -Yvirtpatmat -Xexperimental diff --git a/test/files/pos/virtpatmat_exist3.scala b/test/files/pos/virtpatmat_exist3.scala new file mode 100644 index 0000000000..94385f32c9 --- /dev/null +++ b/test/files/pos/virtpatmat_exist3.scala @@ -0,0 +1,12 @@ +class ReferenceQueue[T] { + def wrapper(jref: ReferenceQueue[_]): ReferenceQueue[T] = + jref match { + case null => null + } + + // def wrapper(jref: ReferenceQueue[_]): ReferenceQueue[T] = OptionMatching.runOrElse(jref)(((x1: ReferenceQueue[_]) => + // (OptionMatching.guard(null.==(x1), x1.asInstanceOf[ReferenceQueue[_]]).flatMap(((x2: ReferenceQueue[_]) => + // OptionMatching.one(null))): Option[ReferenceQueue[T]]).orElse( + // (OptionMatching.zero: Option[ReferenceQueue[T]]))) + // ) +} \ No newline at end of file diff --git a/test/files/pos/virtpatmat_gadt_array.flags b/test/files/pos/virtpatmat_gadt_array.flags new file mode 100644 index 0000000000..9769db9257 --- /dev/null +++ b/test/files/pos/virtpatmat_gadt_array.flags @@ -0,0 +1 @@ + -Yvirtpatmat -Xexperimental diff --git a/test/files/pos/virtpatmat_gadt_array.scala b/test/files/pos/virtpatmat_gadt_array.scala new file mode 100644 index 0000000000..f3332a897f --- /dev/null +++ b/test/files/pos/virtpatmat_gadt_array.scala @@ -0,0 +1,15 @@ +import scala.collection.mutable._ +object Test { + def genericArrayOps[T](xs: Array[T]): ArrayOps[T] = xs match { + case x: Array[AnyRef] => refArrayOps[AnyRef](x).asInstanceOf[ArrayOps[T]] + case null => null + } + // def genericArrayOps[T >: Nothing <: Any](xs: Array[T]): scala.collection.mutable.ArrayOps[T] + // = OptionMatching.runOrElse(xs)(((x1: Array[T]) => + // ((OptionMatching.guard(x1.isInstanceOf[Array[AnyRef]], x1.asInstanceOf[Array[T] with Array[AnyRef]]).flatMap(((x2: Array[T] with Array[AnyRef]) => + // OptionMatching.one(Test.this.refArrayOps[AnyRef](x2).asInstanceOf[scala.collection.mutable.ArrayOps[T]]))): Option[scala.collection.mutable.ArrayOps[T]]).orElse( + // (OptionMatching.guard(null.==(x1), x1.asInstanceOf[Array[T]]).flatMap(((x3: Array[T]) => + // OptionMatching.one(null))): Option[scala.collection.mutable.ArrayOps[T]])): Option[scala.collection.mutable.ArrayOps[T]]).orElse((OptionMatching.zero: Option[scala.collection.mutable.ArrayOps[T]])))) + + def refArrayOps[T <: AnyRef](xs: Array[T]): ArrayOps[T] = new ArrayOps.ofRef[T](xs) +} \ No newline at end of file diff --git a/test/files/pos/virtpatmat_infer_single_1.flags b/test/files/pos/virtpatmat_infer_single_1.flags new file mode 100644 index 0000000000..9769db9257 --- /dev/null +++ b/test/files/pos/virtpatmat_infer_single_1.flags @@ -0,0 +1 @@ + -Yvirtpatmat -Xexperimental diff --git a/test/files/pos/virtpatmat_infer_single_1.scala b/test/files/pos/virtpatmat_infer_single_1.scala new file mode 100644 index 0000000000..b42af956cc --- /dev/null +++ b/test/files/pos/virtpatmat_infer_single_1.scala @@ -0,0 +1,7 @@ +case class TypeBounds(a: Type, b: Type) +class Type { + def bounds: TypeBounds = bounds match { + case TypeBounds(_: this.type, _: this.type) => TypeBounds(this, this) + case oftp => oftp + } +} \ No newline at end of file diff --git a/test/files/pos/virtpatmat_obj_in_case.flags b/test/files/pos/virtpatmat_obj_in_case.flags new file mode 100644 index 0000000000..9769db9257 --- /dev/null +++ b/test/files/pos/virtpatmat_obj_in_case.flags @@ -0,0 +1 @@ + -Yvirtpatmat -Xexperimental diff --git a/test/files/pos/virtpatmat_obj_in_case.scala b/test/files/pos/virtpatmat_obj_in_case.scala new file mode 100644 index 0000000000..496de4c12e --- /dev/null +++ b/test/files/pos/virtpatmat_obj_in_case.scala @@ -0,0 +1,5 @@ +class ObjInCase { + 0 match { + case _ => object o + } +} \ No newline at end of file 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 -- cgit v1.2.3