Skip to content

Commit

Permalink
Adds missing success reduction for catch.
Browse files Browse the repository at this point in the history
Extends test suite too.
  • Loading branch information
dhil committed Feb 16, 2021
1 parent 5d4602a commit 1b59e24
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
3 changes: 3 additions & 0 deletions interpreter/exec/eval.ml
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,9 @@ let rec step (c : config) : config =
| Catch (n, es1, (_, {it = Throwing; _} :: _)), vs ->
vs, [Label (n, [], ([], List.map plain es1)) @@ e.at]

| Catch (_, _, (vs', [])), vs ->
vs' @ vs, []

| Catch (n, es', code'), vs ->
let c' = step {c with code = code'} in
vs, [Catch (n, es', c'.code) @@ e.at]
Expand Down
22 changes: 20 additions & 2 deletions test/core/tinyexn.wast
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
throw
i32.const 0)
(catch
(i32.const 1))))
i32.const 1)))

(func (export "catch-2") (result i32)
(try (result i32)
Expand All @@ -20,12 +20,30 @@
throw
i32.const 1)))
(catch
(i32.const 2))))
i32.const 2)))

(func (export "success-0") (result i32)
(try (result i32)
(do i32.const 0)
(catch i32.const 1)))

(func (export "success-1") (result i32)
(try (result i32)
(do
(try (result i32)
(do
throw
i32.const 0)
(catch
i32.const 1)))
(catch i32.const 2)))

(func (export "uncaught")
(throw))
)

(assert_return (invoke "catch-1") (i32.const 1))
(assert_return (invoke "catch-2") (i32.const 2))
(assert_return (invoke "success-0") (i32.const 0))
(assert_return (invoke "success-1") (i32.const 1))
(assert_uncaught (invoke "uncaught") "uncaught exception")

0 comments on commit 1b59e24

Please sign in to comment.