Skip to content

Commit a1d13cd

Browse files
authored
Add a regression test on capability ordering (#860)
Discovered by @timsueberkrueb: on ffde209 (latest commit made on March 4), this prints: ``` what ``` but on `master` (after #859), it prints the correct solution: ``` Cons(1, Cons(2, Cons(3, Nil()))) Cons(2, Cons(3, Nil())) Cons(1, Cons(3, Nil())) Cons(3, Nil()) Cons(1, Cons(2, Nil())) Cons(2, Nil()) Cons(1, Nil()) Nil() ``` Curiously, this seems to work fine on v0.21 and v0.22, so I'm not sure where the regression happened. 🤷‍♂️ Nevertheless, we really should have this as a regression test if it sometimes magically fails :)
1 parent 90a7f1e commit a1d13cd

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

examples/pos/cap_ordering.check

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Cons(1, Cons(2, Cons(3, Nil())))
2+
Cons(2, Cons(3, Nil()))
3+
Cons(1, Cons(3, Nil()))
4+
Cons(3, Nil())
5+
Cons(1, Cons(2, Nil()))
6+
Cons(2, Nil())
7+
Cons(1, Nil())
8+
Nil()

examples/pos/cap_ordering.effekt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
module cap_ordering
2+
3+
// Regression test for capability ordering
4+
// Fails on 'ffde2091956d25dd3522f316ecb1dfc19a33a93e'
5+
6+
effect flip[A](): A
7+
8+
def subsets[A](list: List[A]): List[A] / {flip[A], flip[Bool]} = list match {
9+
case Nil() => Nil()
10+
case Cons(head, tail) =>
11+
val rest = subsets(tail)
12+
if (do flip[Bool]()) { Cons(head, rest) } else { rest }}
13+
14+
def main() = {
15+
try {
16+
println(subsets([1, 2, 3]))
17+
} with flip[Bool] {
18+
resume(true); resume(false)
19+
} with flip[Int] {
20+
println("what")
21+
}
22+
}

0 commit comments

Comments
 (0)