diff --git a/crates/aiken-lang/src/gen_uplc.rs b/crates/aiken-lang/src/gen_uplc.rs index 659a4796..caac05dc 100644 --- a/crates/aiken-lang/src/gen_uplc.rs +++ b/crates/aiken-lang/src/gen_uplc.rs @@ -4083,6 +4083,7 @@ impl<'a> CodeGenerator<'a> { for arg in arg_vec { term = term.apply(arg.clone()); } + term } }; diff --git a/crates/aiken-lang/src/gen_uplc/builder.rs b/crates/aiken-lang/src/gen_uplc/builder.rs index 7c6edd37..25578b03 100644 --- a/crates/aiken-lang/src/gen_uplc/builder.rs +++ b/crates/aiken-lang/src/gen_uplc/builder.rs @@ -1845,27 +1845,37 @@ pub fn to_data_builtin( func: &DefaultFunction, count: usize, tipo: &Arc, - args: Vec>, + mut args: Vec>, ) -> Term { let mut term: Term = (*func).into(); term = apply_builtin_forces(term, func.force_count()); - for arg in args { - term = term.apply(arg); + if count == 0 { + assert!(args.is_empty()); + + for arg_index in 0..func.arity() { + let temp_var = format!("__item_index_{}", arg_index); + + args.push(Term::var(temp_var)) + } } - let temp_var = "__item_x"; + for (index, arg) in args.into_iter().enumerate() { + if index == 0 || matches!(func, DefaultFunction::MkPairData) { + term = term.apply(convert_type_to_data(arg, tipo)); + } else { + term = term.apply(arg); + } + } if count == 0 { - term = term.apply(Term::var(temp_var)); + for arg_index in (0..func.arity()).rev() { + let temp_var = format!("__item_index_{}", arg_index); + term = term.lambda(temp_var); + } } - term = convert_type_to_data(term, tipo); - - if count == 0 { - term = term.lambda(temp_var); - } term }