From 350d0c76fd267304bfe3e68dd7b4500a79f0224a Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Sat, 1 Feb 2020 10:18:17 -0800 Subject: [PATCH] Add a test tha call_indirect traps produce good errors Closes #178 --- crates/api/tests/traps.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/crates/api/tests/traps.rs b/crates/api/tests/traps.rs index a5dbbadf48c0..610760a3245b 100644 --- a/crates/api/tests/traps.rs +++ b/crates/api/tests/traps.rs @@ -339,3 +339,34 @@ fn mismatched_arguments() -> Result<()> { ); Ok(()) } + +#[test] +fn call_signature_mismatch() -> Result<()> { + let store = Store::default(); + let binary = wat::parse_str( + r#" + (module $a + (func $foo + i32.const 0 + call_indirect) + (func $bar (param i32)) + (start $foo) + + (table 1 anyfunc) + (elem (i32.const 0) 1) + ) + "#, + )?; + + let module = Module::new(&store, &binary)?; + let err = Instance::new(&module, &[]) + .err() + .unwrap() + .downcast::() + .unwrap(); + assert_eq!( + err.message(), + "wasm trap: indirect call type mismatch, source location: @0030" + ); + Ok(()) +}