diff --git a/crates/aiken-lang/src/gen_uplc.rs b/crates/aiken-lang/src/gen_uplc.rs index 37da2f0b..678402e4 100644 --- a/crates/aiken-lang/src/gen_uplc.rs +++ b/crates/aiken-lang/src/gen_uplc.rs @@ -3100,24 +3100,11 @@ impl<'a> CodeGenerator<'a> { } HoistableFunction::Link(_) => todo!("Deal with Link later"), HoistableFunction::CyclicLink(cyclic_func) => { - let (_, HoistableFunction::CyclicFunction { deps, .. }) = functions_to_hoist - .get(cyclic_func) - .unwrap() - .get("") - .unwrap() - else { - unreachable!() - }; + sorted_dep_vec.retain(|(generic_func, variant)| { + !(generic_func == cyclic_func && variant.is_empty()) + }); - for (dep_generic_func, dep_variant) in deps.iter() { - if !(dep_generic_func == &dep.0 && dep_variant == &dep.1) { - sorted_dep_vec.retain(|(generic_func, variant)| { - !(generic_func == dep_generic_func && variant == dep_variant) - }); - - deps_vec.insert(0, (dep_generic_func.clone(), dep_variant.clone())); - } - } + deps_vec.insert(0, (cyclic_func.clone(), "".to_string())); } } } diff --git a/examples/acceptance_tests/066/lib/test2.ak b/examples/acceptance_tests/066/lib/test2.ak new file mode 100644 index 00000000..dbac4dfa --- /dev/null +++ b/examples/acceptance_tests/066/lib/test2.ak @@ -0,0 +1,51 @@ +type Schema { + Integer(Int) + List(List) + Constr(Int, Schema) +} + +fn sum_constr(tag: Int, fields: Schema) -> Int { + tag + sum(fields) +} + +fn sum(schema: Schema) -> Int { + when schema is { + Integer(i) -> i + List(xs) -> sum_list(xs) + Constr(tag, fields) -> sum_constr(tag, fields) + } +} + +fn sum_list(list: List) -> Int { + when list is { + [] -> 0 + [x, ..xs] -> sum(x) + sum_list(xs) + } +} + +test bar() { + sum(List([List([Integer(1), Integer(2)]), Integer(3), Integer(4)])) == 10 +} + +fn prod(schema: Schema) -> Int { + when schema is { + Integer(i) -> i + List(xs) -> prod_list(xs) + Constr(tag, fields) -> prod_constr(tag, fields) + } +} + +fn prod_constr(tag: Int, fields: Schema) -> Int { + tag * prod(fields) + sum(fields) +} + +fn prod_list(list: List) -> Int { + when list is { + [] -> 1 + [x, ..xs] -> prod(x) * prod_list(xs) + } +} + +test sum_prod() { + prod(List([List([Integer(1), Integer(2)]), Integer(3), Integer(4)])) == 24 +}