diff options
-rw-r--r-- | src/parser/wast-parser.cpp | 14 | ||||
-rw-r--r-- | test/lit/parse-bad-assertion.wast | 8 |
2 files changed, 19 insertions, 3 deletions
diff --git a/src/parser/wast-parser.cpp b/src/parser/wast-parser.cpp index 5eaf352b7..0f7887f8f 100644 --- a/src/parser/wast-parser.cpp +++ b/src/parser/wast-parser.cpp @@ -49,7 +49,7 @@ Result<Literals> consts(Lexer& in) { return lits; } -MaybeResult<Action> action(Lexer& in) { +MaybeResult<Action> maybeAction(Lexer& in) { if (in.takeSExprStart("invoke"sv)) { auto id = in.takeID(); auto name = in.takeName(); @@ -79,6 +79,14 @@ MaybeResult<Action> action(Lexer& in) { return {}; } +Result<Action> action(Lexer& in) { + if (auto a = maybeAction(in)) { + CHECK_ERR(a); + return *a; + } + return in.err("expected action"); +} + // (module id? binary string*) // (module id? quote string*) // (module ...) @@ -348,7 +356,7 @@ MaybeResult<Assertion> assertTrap(Lexer& in) { return {}; } auto pos = in.getPos(); - if (auto a = action(in)) { + if (auto a = maybeAction(in)) { CHECK_ERR(a); auto msg = in.takeString(); if (!msg) { @@ -423,7 +431,7 @@ Result<WASTCommand> command(Lexer& in) { CHECK_ERR(cmd); return *cmd; } - if (auto cmd = action(in)) { + if (auto cmd = maybeAction(in)) { CHECK_ERR(cmd); return *cmd; } diff --git a/test/lit/parse-bad-assertion.wast b/test/lit/parse-bad-assertion.wast new file mode 100644 index 000000000..9e6c7ac7f --- /dev/null +++ b/test/lit/parse-bad-assertion.wast @@ -0,0 +1,8 @@ +;; Check that we properly error when an action is missing from an assertion that +;; requires one. Regression test for #6872. + +;; RUN: not wasm-shell %s 2>&1 | filecheck %s + +(assert_exhaustion "wrong, lol") + +;; CHECK: 6:19: error: expected action |