From 1c89809ea205455ec78ad89152b37bd15893e7c9 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Tue, 19 Dec 2023 13:39:01 +0000 Subject: Handle returns from try bodies --- examples/26-effect-handler-nested/shed.toml | 7 ++++ examples/26-effect-handler-nested/src/Example.shed | 42 ++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 examples/26-effect-handler-nested/shed.toml create mode 100644 examples/26-effect-handler-nested/src/Example.shed (limited to 'examples/26-effect-handler-nested') diff --git a/examples/26-effect-handler-nested/shed.toml b/examples/26-effect-handler-nested/shed.toml new file mode 100644 index 00000000..291ca6db --- /dev/null +++ b/examples/26-effect-handler-nested/shed.toml @@ -0,0 +1,7 @@ +[[shed.bins]] +name = "example" +main-namespace = "Example" + +[[shed.examples]] +bin = "example" +expected-output = "a outer\na inner\na inner\nb\na inner\na inner\na outer" diff --git a/examples/26-effect-handler-nested/src/Example.shed b/examples/26-effect-handler-nested/src/Example.shed new file mode 100644 index 00000000..2a8e4781 --- /dev/null +++ b/examples/26-effect-handler-nested/src/Example.shed @@ -0,0 +1,42 @@ +effect A { + fun a() -> Unit; +} + +effect B { + fun b() -> Unit; +} + +pub fun main() ! Io -> Unit { + try { + A.a!(); + + try { + A.a!(); + + try { + A.a!(); + B.b!(); + A.a!(); + } handle B { + fun b() { + print!("b\n"); + resume; + } + } + + A.a!(); + } handle A { + fun a() { + print!("a inner\n"); + resume; + } + } + + A.a!(); + } handle A { + fun a() { + print!("a outer\n"); + resume; + } + } +} -- cgit v1.2.3