Skip to content

Commit

Permalink
fix: builtins using the incorrect data to type conversion when used a…
Browse files Browse the repository at this point in the history
…s a function param.
  • Loading branch information
MicroProofs committed Jun 23, 2023
1 parent db369da commit 226556b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 7 additions & 2 deletions crates/aiken-lang/src/gen_uplc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<Name> = func.into();
Expand Down
7 changes: 7 additions & 0 deletions examples/acceptance_tests/084/lib/tests.ak
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use aiken/builtin.{snd_pair}
use aiken/cbor
use aiken/list

test tuple_when() {
Expand All @@ -20,3 +22,8 @@ test tuple_when() {
)
list.length(filtered) > 0
}

test t() {
trace cbor.diagnostic(list.map([(#"", 20)], snd_pair))
True
}

0 comments on commit 226556b

Please sign in to comment.