| 511 | |
| 512 | #[test] |
| 513 | fn mismatched_arguments() -> Result<()> { |
| 514 | let mut store = Store::<()>::default(); |
| 515 | let binary = wat::parse_str( |
| 516 | r#" |
| 517 | (module $a |
| 518 | (func (export "foo") (param i32)) |
| 519 | ) |
| 520 | "#, |
| 521 | )?; |
| 522 | |
| 523 | let module = Module::new(store.engine(), &binary)?; |
| 524 | let instance = Instance::new(&mut store, &module, &[])?; |
| 525 | let func = instance.get_func(&mut store, "foo").unwrap(); |
| 526 | assert_eq!( |
| 527 | func.call(&mut store, &[], &mut []).unwrap_err().to_string(), |
| 528 | "expected 1 arguments, got 0" |
| 529 | ); |
| 530 | let e = func.call(&mut store, &[Val::F32(0)], &mut []).unwrap_err(); |
| 531 | e.assert_contains("argument type mismatch"); |
| 532 | e.assert_contains("expected i32, found f32"); |
| 533 | assert_eq!( |
| 534 | func.call(&mut store, &[Val::I32(0), Val::I32(1)], &mut []) |
| 535 | .unwrap_err() |
| 536 | .to_string(), |
| 537 | "expected 1 arguments, got 2" |
| 538 | ); |
| 539 | Ok(()) |
| 540 | } |
| 541 | |
| 542 | #[test] |
| 543 | fn call_signature_mismatch() -> Result<()> { |