From 226556bdd6f61b6712d82782ab688719fbfafdfa Mon Sep 17 00:00:00 2001 From: microproofs Date: Fri, 23 Jun 2023 14:30:29 -0400 Subject: [PATCH] fix: builtins using the incorrect data to type conversion when used as a function param. --- CHANGELOG.md | 1 + crates/aiken-lang/src/gen_uplc.rs | 9 +++++++-- examples/acceptance_tests/084/lib/tests.ak | 7 +++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6cc249d2..7541f296 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ - **aiken-lang**: Fix for tuple clause not consuming the next case causing incomplete contracts. Now tuple clause will always consume the next case unless it is the final clause + - **aiken-lang**: Fix for builtins using the incorrect data to type conversion when used as a function param. ## v1.0.10-alpha - 2023-06-13 diff --git a/crates/aiken-lang/src/gen_uplc.rs b/crates/aiken-lang/src/gen_uplc.rs index c6c1a860..68e0709f 100644 --- a/crates/aiken-lang/src/gen_uplc.rs +++ b/crates/aiken-lang/src/gen_uplc.rs @@ -4168,6 +4168,11 @@ impl<'a> CodeGenerator<'a> { arg_vec.push(arg_stack.pop().unwrap()); } + let tipo = match tipo.as_ref() { + Type::Fn { ret, .. } => ret, + _ => &tipo, + }; + let term = match &func { DefaultFunction::IfThenElse | DefaultFunction::ChooseUnit @@ -4181,11 +4186,11 @@ impl<'a> CodeGenerator<'a> { DefaultFunction::FstPair | DefaultFunction::SndPair | DefaultFunction::HeadList => { - builder::undata_builtin(&func, count, &tipo, arg_vec) + builder::undata_builtin(&func, count, tipo, arg_vec) } DefaultFunction::MkCons | DefaultFunction::MkPairData => { - builder::to_data_builtin(&func, count, &tipo, arg_vec) + builder::to_data_builtin(&func, count, tipo, arg_vec) } _ => { let mut term: Term = func.into(); diff --git a/examples/acceptance_tests/084/lib/tests.ak b/examples/acceptance_tests/084/lib/tests.ak index 962b5a6a..e9db5434 100644 --- a/examples/acceptance_tests/084/lib/tests.ak +++ b/examples/acceptance_tests/084/lib/tests.ak @@ -1,3 +1,5 @@ +use aiken/builtin.{snd_pair} +use aiken/cbor use aiken/list test tuple_when() { @@ -20,3 +22,8 @@ test tuple_when() { ) list.length(filtered) > 0 } + +test t() { + trace cbor.diagnostic(list.map([(#"", 20)], snd_pair)) + True +}