change check_validator_args to check type after each arg

This commit is contained in:
microproofs 2024-02-06 19:31:25 -05:00 committed by Kasey
parent 6c6be3f53d
commit 056e3d76ea
1 changed files with 60 additions and 57 deletions

View File

@ -2751,18 +2751,24 @@ impl<'a> CodeGenerator<'a> {
) -> AirTree { ) -> AirTree {
let mut arg_names = vec![]; let mut arg_names = vec![];
let checked_args =
arguments arguments
.iter() .iter()
.enumerate()
.rev() .rev()
.fold(body, |inner_then, (index, arg)| { .with_position()
.fold(body, |inner_then, arg_position| match arg_position {
itertools::Position::First(arg) if has_context => {
let arg_name = arg.arg_name.get_variable_name().unwrap_or("_").to_string();
AirTree::anon_func(vec![arg_name], inner_then)
}
itertools::Position::First(arg)
| itertools::Position::Middle(arg)
| itertools::Position::Last(arg) => {
let arg_name = arg.arg_name.get_variable_name().unwrap_or("_").to_string(); let arg_name = arg.arg_name.get_variable_name().unwrap_or("_").to_string();
let arg_span = arg.location; let arg_span = arg.location;
arg_names.push(arg_name.clone()); arg_names.push(arg_name.clone());
if !(has_context && index == arguments.len() - 1) && &arg_name != "_" {
let param = AirTree::local_var(&arg_name, data()); let param = AirTree::local_var(&arg_name, data());
let actual_type = convert_opaque_type(&arg.tipo, &self.data_types); let actual_type = convert_opaque_type(&arg.tipo, &self.data_types);
@ -2796,7 +2802,7 @@ impl<'a> CodeGenerator<'a> {
} }
}; };
self.assignment( let inner_then = self.assignment(
&Pattern::Var { &Pattern::Var {
location: Span::empty(), location: Span::empty(),
name: arg_name.to_string(), name: arg_name.to_string(),
@ -2811,15 +2817,12 @@ impl<'a> CodeGenerator<'a> {
full_check: true, full_check: true,
msg_func, msg_func,
}, },
) );
} else {
inner_then AirTree::anon_func(vec![arg_name], inner_then)
} }
}); itertools::Position::Only(_) => unreachable!(),
})
arg_names.reverse();
AirTree::anon_func(arg_names, checked_args)
} }
fn hoist_functions_to_validator(&mut self, mut air_tree: AirTree) -> AirTree { fn hoist_functions_to_validator(&mut self, mut air_tree: AirTree) -> AirTree {