Fix error messages reporting number of expected vs actual params
We previously had some off-by-one errors in our error messages and this led to very confusing messages like "expected 0 types, found 0" that were quite annoying to debug as an API consumer.
This commit is contained in:
@@ -347,17 +347,23 @@ macro_rules! impl_wasm_params {
|
||||
|
||||
fn typecheck(mut params: impl ExactSizeIterator<Item = crate::ValType>) -> Result<()> {
|
||||
let mut _n = 0;
|
||||
|
||||
$(
|
||||
match params.next() {
|
||||
Some(t) => $t::typecheck(t)?,
|
||||
None => bail!("expected {} types, found {}", $n, _n),
|
||||
Some(t) => {
|
||||
_n += 1;
|
||||
$t::typecheck(t)?
|
||||
},
|
||||
None => bail!("expected {} types, found {}", $n, params.len() + _n),
|
||||
}
|
||||
_n += 1;
|
||||
)*
|
||||
|
||||
match params.next() {
|
||||
None => Ok(()),
|
||||
Some(_) => bail!("expected {} types, found {}", $n, params.len() + _n),
|
||||
Some(_) => {
|
||||
_n += 1;
|
||||
bail!("expected {} types, found {}", $n, params.len() + _n)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user