diff --git a/crates/aiken-lang/src/tipo/infer.rs b/crates/aiken-lang/src/tipo/infer.rs index 7c029681..07e8db42 100644 --- a/crates/aiken-lang/src/tipo/infer.rs +++ b/crates/aiken-lang/src/tipo/infer.rs @@ -262,81 +262,79 @@ fn infer_definition( let temp_params = params.iter().cloned().chain(fun.arguments); fun.arguments = temp_params.collect(); - if let Definition::Fn(mut typed_fun) = infer_definition( + let Definition::Fn(mut typed_fun) = infer_definition( Definition::Fn(fun), module_name, hydrators, environment, tracing, kind, - )? { - if !typed_fun.return_type.is_bool() { - return Err(Error::ValidatorMustReturnBool { - return_type: typed_fun.return_type.clone(), - location: typed_fun.location, - }); - } - - let typed_params = typed_fun.arguments.drain(0..params_length).collect(); - - if typed_fun.arguments.len() < 2 || typed_fun.arguments.len() > 3 { - return Err(Error::IncorrectValidatorArity { - count: typed_fun.arguments.len() as u32, - location: typed_fun.location, - }); - } - - let typed_other_fun = other_fun - .map(|mut other| -> Result { - let params = params.into_iter().chain(other.arguments); - other.arguments = params.collect(); - - if let Definition::Fn(mut other_typed_fun) = infer_definition( - Definition::Fn(other), - module_name, - hydrators, - environment, - tracing, - kind, - )? { - if !other_typed_fun.return_type.is_bool() { - return Err(Error::ValidatorMustReturnBool { - return_type: other_typed_fun.return_type.clone(), - location: other_typed_fun.location, - }); - } - - other_typed_fun.arguments.drain(0..params_length); - - if other_typed_fun.arguments.len() < 2 - || other_typed_fun.arguments.len() > 3 - { - return Err(Error::IncorrectValidatorArity { - count: other_typed_fun.arguments.len() as u32, - location: other_typed_fun.location, - }); - } - - Ok(other_typed_fun) - } else { - unreachable!( - "validator definition inferred as something other than a function?" - ) - } - }) - .transpose(); - - Ok(Definition::Validator(Validator { - doc, - end_position, - fun: typed_fun, - other_fun: typed_other_fun?, - location, - params: typed_params, - })) - } else { + )? else { unreachable!("validator definition inferred as something other than a function?") + }; + + if !typed_fun.return_type.is_bool() { + return Err(Error::ValidatorMustReturnBool { + return_type: typed_fun.return_type.clone(), + location: typed_fun.location, + }); } + + let typed_params = typed_fun.arguments.drain(0..params_length).collect(); + + if typed_fun.arguments.len() < 2 || typed_fun.arguments.len() > 3 { + return Err(Error::IncorrectValidatorArity { + count: typed_fun.arguments.len() as u32, + location: typed_fun.location, + }); + } + + let typed_other_fun = other_fun + .map(|mut other| -> Result { + let params = params.into_iter().chain(other.arguments); + other.arguments = params.collect(); + + let Definition::Fn(mut other_typed_fun) = infer_definition( + Definition::Fn(other), + module_name, + hydrators, + environment, + tracing, + kind, + )? else { + unreachable!( + "validator definition inferred as something other than a function?" + ) + }; + + if !other_typed_fun.return_type.is_bool() { + return Err(Error::ValidatorMustReturnBool { + return_type: other_typed_fun.return_type.clone(), + location: other_typed_fun.location, + }); + } + + other_typed_fun.arguments.drain(0..params_length); + + if other_typed_fun.arguments.len() < 2 || other_typed_fun.arguments.len() > 3 { + return Err(Error::IncorrectValidatorArity { + count: other_typed_fun.arguments.len() as u32, + location: other_typed_fun.location, + }); + } + + Ok(other_typed_fun) + }) + .transpose(); + + Ok(Definition::Validator(Validator { + doc, + end_position, + fun: typed_fun, + other_fun: typed_other_fun?, + location, + params: typed_params, + })) } Definition::Test(f) => {