From 87eb4ca3b406c8e75263bbc9c160c4046e95af09 Mon Sep 17 00:00:00 2001 From: Kasey White Date: Mon, 20 Feb 2023 00:51:03 -0500 Subject: [PATCH] feat: handle single constr when with multiple branches Add case to acceptance test 40 Add special case for top level single constr in a when. --- crates/aiken-lang/src/uplc.rs | 29 +++++++++++++++++----- examples/acceptance_tests/040/lib/tests.ak | 9 +++++++ 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/crates/aiken-lang/src/uplc.rs b/crates/aiken-lang/src/uplc.rs index 0e451146..31407969 100644 --- a/crates/aiken-lang/src/uplc.rs +++ b/crates/aiken-lang/src/uplc.rs @@ -756,12 +756,29 @@ impl<'a> CodeGenerator<'a> { scope.clone(), ); - ir_stack.push(Air::Clause { - scope, - tipo: subject_type.clone(), - complex_clause: *clause_properties.is_complex_clause(), - subject_name, - }); + let data_type = + lookup_data_type_by_tipo(self.data_types.clone(), &subject_type).unwrap(); + + if data_type.constructors.len() > 1 { + ir_stack.push(Air::Clause { + scope, + tipo: subject_type.clone(), + complex_clause: *clause_properties.is_complex_clause(), + subject_name, + }); + } else { + ir_stack.push(Air::Clause { + scope: scope.clone(), + tipo: subject_type.clone(), + complex_clause: *clause_properties.is_complex_clause(), + subject_name, + }); + + ir_stack.push(Air::Int { + scope, + value: "0".to_string(), + }); + } } ClauseProperties::ListClause { original_subject_name, diff --git a/examples/acceptance_tests/040/lib/tests.ak b/examples/acceptance_tests/040/lib/tests.ak index 0367517b..23903b7c 100644 --- a/examples/acceptance_tests/040/lib/tests.ak +++ b/examples/acceptance_tests/040/lib/tests.ak @@ -73,3 +73,12 @@ test single_field_expect() { expect CreateVoteBatch { id } = redeemer id == #"" } + +test single_when() { + let redeemer = CreateVoteBatch { id: #"" } + let x = when redeemer is { + CreateVoteBatch { id } -> id == #"" + _ -> False + } + x == True +}