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.
This commit is contained in:
Kasey White 2023-02-20 00:51:03 -05:00 committed by Lucas
parent 95fce14b75
commit 87eb4ca3b4
2 changed files with 32 additions and 6 deletions

View File

@ -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,

View File

@ -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
}