From 11ada63fbb7ba982c92f22fa1fb0e39cebe3f194 Mon Sep 17 00:00:00 2001 From: Thomas Lively <7121787+tlively@users.noreply.github.com> Date: Fri, 18 Feb 2022 10:08:13 -0800 Subject: Include type names in error messages from building (#4517) Instead of just reporting the type index that causes an error when building types, report the name of the responsible type when parsing the text format. --- src/wasm/wasm-s-parser.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src') 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; -- cgit v1.2.3