Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions crates/wasm-wave/src/untyped.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@

use alloc::{borrow::Cow, vec::Vec};

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

/// An UntypedValue is a parsed but not type-checked WAVE value.
#[derive(Clone, Debug)]
Expand Down Expand Up @@ -121,11 +126,21 @@ impl<'source> UntypedFuncCall<'source> {
/// be returned as `none` values.
pub fn to_wasm_params<'types, V: WasmValue + 'static>(
&self,
types: impl IntoIterator<Item = &'types V::Type>,
types: impl IntoIterator<Item = &'types V::Type, IntoIter: ExactSizeIterator>,
) -> Result<Vec<V>, ParserError> {
match &self.params {
Some(params) => params.to_wasm_params(types, self.source()),
None => Ok(Vec::new()),
None => {
let num_params = types.into_iter().len();
if num_params > 0 {
return Err(ParserError::with_detail(
ParserErrorKind::InvalidParams,
self.name.span(),
alloc::format!("no params provided, but {num_params} required"),
));
}
Ok(Vec::new())
}
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions crates/wasm-wave/tests/ui/reject-strings.out
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,5 @@ unexpected token: LabelOrKeyword at 25..30
// Multiline invalid escapes
invalid character escape at 30..31
invalid character escape at 27..28
// Missing argument
invalid params: no params provided, but 1 required at 0..6
4 changes: 3 additions & 1 deletion crates/wasm-wave/tests/ui/reject-strings.waves
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,6 @@ Invalid surrogate: \u{d800}
""");
string("""
Invalid escape: \j
""");
""");
// Missing argument
string();
Loading