diff options
author | Adriaan Moors <adriaan.moors@epfl.ch> | 2011-10-20 22:29:20 +0000 |
---|---|---|
committer | Adriaan Moors <adriaan.moors@epfl.ch> | 2011-10-20 22:29:20 +0000 |
commit | 8a9fd64129926eea35f7dca181242855f14e153f (patch) | |
tree | 4defd18749999b6e14d9fba1ccc5e1507b453a64 /test/files/pos | |
parent | 891a6e466b1b22b93c091d590178f7e5410f608e (diff) | |
download | scala-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/pos')
-rw-r--r-- | test/files/pos/virtpatmat_castbinder.flags | 1 | ||||
-rw-r--r-- | test/files/pos/virtpatmat_castbinder.scala | 15 | ||||
-rw-r--r-- | test/files/pos/virtpatmat_exist1.flags | 1 | ||||
-rw-r--r-- | test/files/pos/virtpatmat_exist1.scala | 24 | ||||
-rw-r--r-- | test/files/pos/virtpatmat_exist2.flags | 1 | ||||
-rw-r--r-- | test/files/pos/virtpatmat_exist2.scala | 20 | ||||
-rw-r--r-- | test/files/pos/virtpatmat_exist3.flags | 1 | ||||
-rw-r--r-- | test/files/pos/virtpatmat_exist3.scala | 12 | ||||
-rw-r--r-- | test/files/pos/virtpatmat_gadt_array.flags | 1 | ||||
-rw-r--r-- | test/files/pos/virtpatmat_gadt_array.scala | 15 | ||||
-rw-r--r-- | test/files/pos/virtpatmat_infer_single_1.flags | 1 | ||||
-rw-r--r-- | test/files/pos/virtpatmat_infer_single_1.scala | 7 | ||||
-rw-r--r-- | test/files/pos/virtpatmat_obj_in_case.flags | 1 | ||||
-rw-r--r-- | test/files/pos/virtpatmat_obj_in_case.scala | 5 |
14 files changed, 105 insertions, 0 deletions
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 |