aboutsummaryrefslogtreecommitdiff
path: root/tests/patmat/exhausting.scala
diff options
context:
space:
mode:
authorliu fengyun <liufengyunchina@gmail.com>2016-07-21 10:45:14 +0200
committerliu fengyun <liufengyunchina@gmail.com>2016-08-24 10:26:59 +0200
commitcc02243fbe8b7290265e1bdf540e4c2f256df199 (patch)
treebd83dcabb8de09fa48b9373b9431ef8c481da5ed /tests/patmat/exhausting.scala
parent1a7618f32c6d8060c3a87ce633645440d500aa7a (diff)
downloaddotty-cc02243fbe8b7290265e1bdf540e4c2f256df199.tar.gz
dotty-cc02243fbe8b7290265e1bdf540e4c2f256df199.tar.bz2
dotty-cc02243fbe8b7290265e1bdf540e4c2f256df199.zip
add test set for exhaustivity and redundancy check
Diffstat (limited to 'tests/patmat/exhausting.scala')
-rw-r--r--tests/patmat/exhausting.scala58
1 files changed, 58 insertions, 0 deletions
diff --git a/tests/patmat/exhausting.scala b/tests/patmat/exhausting.scala
new file mode 100644
index 000000000..03e8198dd
--- /dev/null
+++ b/tests/patmat/exhausting.scala
@@ -0,0 +1,58 @@
+object Test {
+ sealed abstract class Foo[T]
+ case object Bar1 extends Foo[Int]
+ case object Bar2 extends Foo[String]
+ case object Bar3 extends Foo[Any]
+
+ def ex1[T](xs: List[T]) = xs match {
+ case ys: List[_] => "ok"
+ }
+ def ex2[T](xx: (Foo[T], Foo[T])) = xx match {
+ case (Bar1, Bar1) => ()
+ case (_, Bar1) => ()
+ case (_, Bar3) => ()
+ case (_, Bar2) => ()
+ }
+ def ex3[T](xx: (Foo[T], Foo[T])) = xx match {
+ case (_: Foo[_], _: Foo[_]) => ()
+ }
+
+ // fails for: ::(_, Nil), ::(_, ::(_, ::(_, _))), ...
+ def fail1[T](xs: List[T]) = xs match {
+ case Nil => "ok"
+ case x :: y :: Nil => "ok"
+ }
+
+ // fails for: Nil
+ def fail2[T](xs: List[T]) = xs match {
+ case _ :: _ => "ok"
+ }
+
+ // fails for: ::(<not in (2, 1)>, _)
+ def fail3a(xs: List[Int]) = xs match {
+ case 1 :: _ =>
+ case 2 :: _ =>
+ case Nil =>
+ }
+
+ // fails for: Bar3
+ def fail3[T](x: Foo[T]) = x match {
+ case Bar1 => "ok"
+ case Bar2 => "ok"
+ }
+ // fails for: (Bar2, Bar2)
+ def fail4[T <: AnyRef](xx: (Foo[T], Foo[T])) = xx match {
+ case (Bar1, Bar1) => ()
+ case (Bar2, Bar3) => ()
+ case (Bar3, _) => ()
+ }
+ // fails for: (Bar1, Bar2)
+ // fails for: (Bar1, Bar3)
+ // fails for: (Bar2, Bar1)
+ // fails for: (Bar2, Bar2)
+ def fail5[T](xx: (Foo[T], Foo[T])) = xx match {
+ case (Bar1, Bar1) => ()
+ case (Bar2, Bar3) => ()
+ case (Bar3, _) => ()
+ }
+}