Typed funcref: handle unbound type names in validation
An example program like the following should fail during validation:
;;; TOOL: wat2wasm
;;; ARGS: --enable-function-references
;;; ERROR: 1
(module
(func (param $f (ref $x)) (result f32))
)
(;; STDERR ;;;
;;; STDERR ;;)
Because the ref $x is unbound.
Right now this will trigger an assertion failure:
+wat2wasm: ../../../src/wast-parser.cc:283: void wabt::(anonymous namespace)::ResolveTypeName(const wabt::Module &, wabt::Type &, wabt::Index, const std::unordered_map<uint32_t, std::string> &): Assertion `type_index != kInvalidIndex' failed.
which is erroring too soon. Instead, the representation of parsed types should probably include a Var so that the name lookup can be done in validation, when the entire module state is built up already.
I am new here, and may misunderstand something but the IsModuleField(PeekPair()) while loop completes in WastParser::ParseModuleFieldList before calling ResolveFuncTypes(module, errors_), so all types should be available.
https://github.com/WebAssembly/wabt/blob/main/src/wast-parser.cc#L1165
I try to figure out what is happening here.
#1892 eliminates the assert issue