Skip to content

Commit 57c5677

Browse files
committed
wasm-wave: catch error in UntypedFuncCall::to_wasm_params
1 parent 4a72fcd commit 57c5677

3 files changed

Lines changed: 20 additions & 5 deletions

File tree

crates/wasm-wave/src/untyped.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use alloc::{borrow::Cow, vec::Vec};
44

5-
use crate::{Parser, WasmValue, ast::Node, lex::Keyword, parser::ParserError};
5+
use crate::{Parser, WasmValue, ast::Node, lex::Keyword, parser::{ParserError, ParserErrorKind}};
66

77
/// An UntypedValue is a parsed but not type-checked WAVE value.
88
#[derive(Clone, Debug)]
@@ -121,11 +121,22 @@ impl<'source> UntypedFuncCall<'source> {
121121
/// be returned as `none` values.
122122
pub fn to_wasm_params<'types, V: WasmValue + 'static>(
123123
&self,
124-
types: impl IntoIterator<Item = &'types V::Type>,
125-
) -> Result<Vec<V>, ParserError> {
124+
types: impl IntoIterator<Item = &'types V::Type, IntoIter: ExactSizeIterator>,
125+
) -> Result<Vec<V>, ParserError>
126+
{
126127
match &self.params {
127128
Some(params) => params.to_wasm_params(types, self.source()),
128-
None => Ok(Vec::new()),
129+
None => {
130+
let num_params = types.into_iter().len();
131+
if num_params > 0 {
132+
return Err(ParserError::with_detail(
133+
ParserErrorKind::InvalidParams,
134+
self.name.clone(),
135+
alloc::format!("no params provided, but {num_params} required")
136+
));
137+
}
138+
Ok(Vec::new())
139+
}
129140
}
130141
}
131142
}

crates/wasm-wave/tests/ui/reject-strings.out

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,5 @@ unexpected token: LabelOrKeyword at 25..30
3030
// Multiline invalid escapes
3131
invalid character escape at 30..31
3232
invalid character escape at 27..28
33+
// Missing argument
34+
invalid params: no params provided, but 1 required at 0..6

crates/wasm-wave/tests/ui/reject-strings.waves

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,6 @@ Invalid surrogate: \u{d800}
4343
""");
4444
string("""
4545
Invalid escape: \j
46-
""");
46+
""");
47+
// Missing argument
48+
string();

0 commit comments

Comments
 (0)