diff options
author | Thomas Lively <7121787+tlively@users.noreply.github.com> | 2022-02-18 10:08:13 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-18 10:08:13 -0800 |
commit | 11ada63fbb7ba982c92f22fa1fb0e39cebe3f194 (patch) | |
tree | 07b49625c44cbca91db24da065b7003393ce7410 /src | |
parent | 6810b60d7281d3e847692fdfb06faf32c9a09e59 (diff) | |
download | binaryen-11ada63fbb7ba982c92f22fa1fb0e39cebe3f194.tar.gz binaryen-11ada63fbb7ba982c92f22fa1fb0e39cebe3f194.tar.bz2 binaryen-11ada63fbb7ba982c92f22fa1fb0e39cebe3f194.zip |
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.
Diffstat (limited to 'src')
-rw-r--r-- | src/wasm/wasm-s-parser.cpp | 11 |
1 files changed, 10 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; |