diff options
author | Martin Odersky <odersky@gmail.com> | 2017-02-10 11:36:25 +1100 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2017-04-04 13:29:38 +0200 |
commit | d3b2c37b9fb4211ade0660c3985f9f14a0ffa505 (patch) | |
tree | 58f7467f2871ca814c136a985d676c9afb16d7b6 | |
parent | a5345a38c151472f80e56eaaa2ce764edde3ad79 (diff) | |
download | dotty-d3b2c37b9fb4211ade0660c3985f9f14a0ffa505.tar.gz dotty-d3b2c37b9fb4211ade0660c3985f9f14a0ffa505.tar.bz2 dotty-d3b2c37b9fb4211ade0660c3985f9f14a0ffa505.zip |
New test case
-rw-r--r-- | tests/pos/enum-List-control.scala | 14 | ||||
-rw-r--r-- | tests/run/enum-Tree.check | 1 | ||||
-rw-r--r-- | tests/run/enum-Tree.scala | 29 |
3 files changed, 44 insertions, 0 deletions
diff --git a/tests/pos/enum-List-control.scala b/tests/pos/enum-List-control.scala new file mode 100644 index 000000000..d9df176d1 --- /dev/null +++ b/tests/pos/enum-List-control.scala @@ -0,0 +1,14 @@ +abstract sealed class List[T] extends Enum +object List { + final case class Cons[T](x: T, xs: List[T]) extends List[T] { + def enumTag = 0 + } + final case class Nil[T]() extends List[T] { + def enumTag = 1 + } +} +object Test { + import List._ + val xs = Cons(1, Cons(2, Cons(3, Nil()))) + def main(args: Array[String]) = println(xs) +} diff --git a/tests/run/enum-Tree.check b/tests/run/enum-Tree.check new file mode 100644 index 000000000..02f5151be --- /dev/null +++ b/tests/run/enum-Tree.check @@ -0,0 +1 @@ +If(IsZero(Pred(Succ(Zero))),Succ(Succ(Zero)),Pred(Pred(Zero))) --> 2 diff --git a/tests/run/enum-Tree.scala b/tests/run/enum-Tree.scala new file mode 100644 index 000000000..ef5bd7a57 --- /dev/null +++ b/tests/run/enum-Tree.scala @@ -0,0 +1,29 @@ +enum Tree[T] { + case True extends Tree[Boolean] + case False extends Tree[Boolean] + case Zero extends Tree[Int] + case Succ(n: Tree[Int]) extends Tree[Int] + case Pred(n: Tree[Int]) extends Tree[Int] + case IsZero(n: Tree[Int]) extends Tree[Boolean] + case If(cond: Tree[Boolean], thenp: Tree[T], elsep: Tree[T]) +} + +object Test { + import Tree._ + + def eval[T](e: Tree[T]): T = e match { + case True => true + case False => false + case Zero => 0 + case Succ(f) => eval(f) + 1 + case Pred(f) => eval(f) - 1 + case IsZero(f) => eval(f) == 0 + case If(cond, thenp, elsep) => if (eval(cond)) eval(thenp) else eval(elsep) + } + + val data = If(IsZero(Pred(Succ(Zero))), Succ(Succ(Zero)), Pred(Pred(Zero))) + + def main(args: Array[String]) = { + println(s"$data --> ${eval(data)}") + } +} |