Skip to content

Commit 2951700

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

3 files changed

Lines changed: 23 additions & 4 deletions

File tree

crates/wasm-wave/src/untyped.rs

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

5-
use crate::{Parser, WasmValue, ast::Node, lex::Keyword, parser::ParserError};
5+
use crate::{
6+
Parser, WasmValue,
7+
ast::Node,
8+
lex::Keyword,
9+
parser::{ParserError, ParserErrorKind},
10+
};
611

712
/// An UntypedValue is a parsed but not type-checked WAVE value.
813
#[derive(Clone, Debug)]
@@ -121,11 +126,21 @@ impl<'source> UntypedFuncCall<'source> {
121126
/// be returned as `none` values.
122127
pub fn to_wasm_params<'types, V: WasmValue + 'static>(
123128
&self,
124-
types: impl IntoIterator<Item = &'types V::Type>,
129+
types: impl IntoIterator<Item = &'types V::Type, IntoIter: ExactSizeIterator>,
125130
) -> Result<Vec<V>, ParserError> {
126131
match &self.params {
127132
Some(params) => params.to_wasm_params(types, self.source()),
128-
None => Ok(Vec::new()),
133+
None => {
134+
let num_params = types.into_iter().len();
135+
if num_params > 0 {
136+
return Err(ParserError::with_detail(
137+
ParserErrorKind::InvalidParams,
138+
self.name.span(),
139+
alloc::format!("no params provided, but {num_params} required"),
140+
));
141+
}
142+
Ok(Vec::new())
143+
}
129144
}
130145
}
131146
}

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)