diff --git a/crates/aiken-lang/src/gen_uplc.rs b/crates/aiken-lang/src/gen_uplc.rs index 2cd92a812..4a3638bb0 100644 --- a/crates/aiken-lang/src/gen_uplc.rs +++ b/crates/aiken-lang/src/gen_uplc.rs @@ -2522,7 +2522,7 @@ impl<'a> CodeGenerator<'a> { if dependency_map.contains_key(&function.0) { dependency_map.shift_remove(&function.0); } - dependency_map.insert(function.0, function.1); + func_keys.extend( funct_comp .dependencies @@ -2535,6 +2535,15 @@ impl<'a> CodeGenerator<'a> { }) .collect_vec(), ); + + let func_scope = func_index_map.get(&function.0).unwrap().clone(); + + for dep in funct_comp.dependencies.iter() { + let Some(dep_scope) = func_index_map.get_mut(dep) else { unreachable!("Missing dependency scope.")}; + + *dep_scope = dep_scope.common_ancestor(&func_scope); + } + dependency_map.insert(function.0, function.1); } dependency_vec.extend( @@ -2816,9 +2825,7 @@ impl<'a> CodeGenerator<'a> { for (index, ir) in ir_stack.to_vec().iter().enumerate().rev() { match ir { Air::Var { - scope, - constructor, - .. + scope, constructor, .. } => { if let ValueConstructorVariant::ModuleFn { name, diff --git a/crates/aiken-lang/src/gen_uplc/builder.rs b/crates/aiken-lang/src/gen_uplc/builder.rs index f2f967879..0506a61eb 100644 --- a/crates/aiken-lang/src/gen_uplc/builder.rs +++ b/crates/aiken-lang/src/gen_uplc/builder.rs @@ -1473,7 +1473,7 @@ pub fn handle_func_dependencies( let dep_scope = func_index_map.get(&dependency).unwrap(); - if dep_scope.common_ancestor(func_scope) == *func_scope + if (dep_scope.common_ancestor(func_scope) == *func_scope && !depend_comp.args.is_empty()) || function_component.args.is_empty() { let mut recursion_ir = vec![];