From a5a073462964f604ad6813b9d6158c75d219241b Mon Sep 17 00:00:00 2001 From: microproofs Date: Wed, 27 Mar 2024 15:52:23 -0400 Subject: [PATCH] fix: casting a field type to Data with expect and traces on was assuming the raw Data was of type constr --- crates/aiken-lang/src/gen_uplc/builder.rs | 2 ++ examples/acceptance_tests/099/lib/other.ak | 32 ++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 examples/acceptance_tests/099/lib/other.ak diff --git a/crates/aiken-lang/src/gen_uplc/builder.rs b/crates/aiken-lang/src/gen_uplc/builder.rs index e0246a15..519ce5fc 100644 --- a/crates/aiken-lang/src/gen_uplc/builder.rs +++ b/crates/aiken-lang/src/gen_uplc/builder.rs @@ -1192,6 +1192,8 @@ pub fn unknown_data_to_type_debug( .apply(term) } else if field_type.is_ml_result() { panic!("ML Result not supported") + } else if field_type.is_data() { + term } else { Term::var("__val") .delayed_choose_data( diff --git a/examples/acceptance_tests/099/lib/other.ak b/examples/acceptance_tests/099/lib/other.ak new file mode 100644 index 00000000..21cf1094 --- /dev/null +++ b/examples/acceptance_tests/099/lib/other.ak @@ -0,0 +1,32 @@ +pub type PublicKeyHash = + ByteArray + +pub type ByteArrayDataPair { + key: ByteArray, + value: Data, +} + +pub type ReferenceDatum { + data: List, + controller: PublicKeyHash, +} + +pub fn find_data(datas: List, key: ByteArray) -> Data { + when datas is { + [] -> fail @"Data Structure Not Found" + [d, ..ds] -> + if d.key == key { + d.value + } else { + find_data(ds, key) + } + } +} + +test thing() { + let stuff: Data = + ReferenceDatum([ByteArrayDataPair("key", "value")], "controller") + + expect other: ReferenceDatum = stuff + other == other +}