diff options
author | Thomas Lively <tlively@google.com> | 2024-08-06 20:01:54 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-06 17:01:54 -0700 |
commit | 23a1a1aacc0dd14767ca8c53a034b7c6bb4acf52 (patch) | |
tree | d0c7a8f88072a2b1fc77a8ec655eca732459481f | |
parent | 0c269482097ae9da62a690b0ace406e2d2109c48 (diff) | |
download | binaryen-23a1a1aacc0dd14767ca8c53a034b7c6bb4acf52.tar.gz binaryen-23a1a1aacc0dd14767ca8c53a034b7c6bb4acf52.tar.bz2 binaryen-23a1a1aacc0dd14767ca8c53a034b7c6bb4acf52.zip |
[parser] Fix bug when printing type builder errors (#6817)
The type index from the TypeBuilder error was mapped to a file location
incorrectly, resulting in an assertion failure.
Fixes #6816.
-rw-r--r-- | src/parser/parse-2-typedefs.cpp | 2 | ||||
-rw-r--r-- | test/lit/parse-bad-supertype-8616.wast | 11 |
2 files changed, 12 insertions, 1 deletions
diff --git a/src/parser/parse-2-typedefs.cpp b/src/parser/parse-2-typedefs.cpp index 90a84941d..97ba247bd 100644 --- a/src/parser/parse-2-typedefs.cpp +++ b/src/parser/parse-2-typedefs.cpp @@ -34,7 +34,7 @@ Result<> parseTypeDefs( if (auto* err = built.getError()) { std::stringstream msg; msg << "invalid type: " << err->reason; - return ctx.in.err(decls.typeDefs[err->index].pos, msg.str()); + return ctx.in.err(decls.subtypeDefs[err->index].pos, msg.str()); } types = *built; // Record type names on the module and in typeNames. diff --git a/test/lit/parse-bad-supertype-8616.wast b/test/lit/parse-bad-supertype-8616.wast new file mode 100644 index 000000000..c7c3dc957 --- /dev/null +++ b/test/lit/parse-bad-supertype-8616.wast @@ -0,0 +1,11 @@ +;; RUN: not wasm-opt %s 2>&1 | filecheck %s + +;; CHECK: Fatal: 9:2: error: invalid type: Heap type has an undeclared supertype + +;; Regression test for a parser bug that caused an assertion failure in this case. +(module + (rec + (type $A (sub (struct (field i32)))) + (type $B (sub $B (struct (field i32) (field i32)))) + ) +)
\ No newline at end of file |