From bffa6781780763a6eb9acef204166eee184cfaad Mon Sep 17 00:00:00 2001 From: microproofs Date: Sat, 9 Mar 2024 10:04:30 -0500 Subject: [PATCH] fix: mutually recursive zero arg functions needed to have their function bodies delayed --- crates/aiken-lang/src/gen_uplc.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/crates/aiken-lang/src/gen_uplc.rs b/crates/aiken-lang/src/gen_uplc.rs index d0877405..c9edd1e8 100644 --- a/crates/aiken-lang/src/gen_uplc.rs +++ b/crates/aiken-lang/src/gen_uplc.rs @@ -4201,7 +4201,7 @@ impl<'a> CodeGenerator<'a> { } } else if let Term::Apply { .. } = &term { // Case for mutually recursive zero arg functions - Some(term) + Some(term.force()) } else { unreachable!( "Shouldn't call anything other than var or apply {:#?}", @@ -4493,8 +4493,12 @@ impl<'a> CodeGenerator<'a> { for (params, func_body) in cyclic_functions.into_iter() { let mut function = func_body; - for param in params.iter().rev() { - function = function.lambda(param); + if params.is_empty() { + function = function.delay(); + } else { + for param in params.iter().rev() { + function = function.lambda(param); + } } // We basically Scott encode our function bodies and use the chooser function