When a catch block is reached with an exception reference, it can be declared with a non-nullable (ref exn), e.g. this is a valid WebAssembly module:
(module
(tag $my_error)
(func $try_and_catch
(block $handler (result (ref exn))
(try_table (catch_ref $my_error $handler)
)
(return)
)
(drop)
)
(export "main" (func $try_and_catch))
)
wasm-tools validate agrees with this being valid, I used wasm-tools parse to turn it into a binary module. Attempting to load this module with endive fails:
Exception in thread "main" run.endive.wasm.InvalidException: type mismatch: instruction requires [ref[-23]] but stack has [refnull[-23]]
at run.endive.wasm.Validator.validateFunction(Validator.java:2799)
at run.endive.wasm.Validator.validateFunctions(Validator.java:906)
at run.endive.wasm.WasmModule$Builder.build(WasmModule.java:289)
at run.endive.wasm.Parser.parse(Parser.java:301)
at run.endive.wasm.Parser.parse(Parser.java:262)
at run.endive.wasm.Parser.parse(Parser.java:254)
The reason is that in validateFunction, validating a try_block pushes a ValType.ExnRef for CATCH_REF and CATCH_ALL_REF. exnref (aka (ref null exn) is not the same as (ref exn) though, which is what is required by the spec.
When a catch block is reached with an exception reference, it can be declared with a non-nullable
(ref exn), e.g. this is a valid WebAssembly module:wasm-tools validateagrees with this being valid, I usedwasm-tools parseto turn it into a binary module. Attempting to load this module with endive fails:The reason is that in
validateFunction, validating atry_blockpushes aValType.ExnRefforCATCH_REFandCATCH_ALL_REF.exnref(aka(ref null exn)is not the same as(ref exn)though, which is what is required by the spec.