diff options
-rw-r--r-- | src/wasm/wasm-s-parser.cpp | 11 | ||||
-rw-r--r-- | test/lit/parse-bad-supertype.wast | 9 |
2 files changed, 19 insertions, 1 deletions
diff --git a/src/wasm/wasm-s-parser.cpp b/src/wasm/wasm-s-parser.cpp index 0cb58746c..6da0316c8 100644 --- a/src/wasm/wasm-s-parser.cpp +++ b/src/wasm/wasm-s-parser.cpp @@ -936,7 +936,16 @@ void SExpressionWasmBuilder::preParseHeapTypes(Element& module) { auto result = builder.build(); if (auto* err = result.getError()) { - Fatal() << "Invalid type: " << err->reason << " at index " << err->index; + // Find the name to provide a better error message. + std::stringstream msg; + msg << "Invalid type: " << err->reason; + for (auto& [name, index] : typeIndices) { + if (index == err->index) { + Fatal() << msg.str() << " at type $" << name; + } + } + // No name, just report the index. + Fatal() << msg.str() << " at index " << err->index; } types = *result; diff --git a/test/lit/parse-bad-supertype.wast b/test/lit/parse-bad-supertype.wast new file mode 100644 index 000000000..3a50efecf --- /dev/null +++ b/test/lit/parse-bad-supertype.wast @@ -0,0 +1,9 @@ +;; Test that an invalid supertype results in a useful error message + +;; RUN: not wasm-opt %s -all --nominal 2>&1 | filecheck %s + +;; CHECK: Fatal: Invalid type: Heap type has an invalid supertype at type $sub +(module + (type $super (struct_subtype i32 data)) + (type $sub (struct_subtype i64 $super)) +)
\ No newline at end of file |