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:
parent
95fce14b75
commit
87eb4ca3b4
|
@ -756,12 +756,29 @@ impl<'a> CodeGenerator<'a> {
|
||||||
scope.clone(),
|
scope.clone(),
|
||||||
);
|
);
|
||||||
|
|
||||||
ir_stack.push(Air::Clause {
|
let data_type =
|
||||||
scope,
|
lookup_data_type_by_tipo(self.data_types.clone(), &subject_type).unwrap();
|
||||||
tipo: subject_type.clone(),
|
|
||||||
complex_clause: *clause_properties.is_complex_clause(),
|
if data_type.constructors.len() > 1 {
|
||||||
subject_name,
|
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 {
|
ClauseProperties::ListClause {
|
||||||
original_subject_name,
|
original_subject_name,
|
||||||
|
|
|
@ -73,3 +73,12 @@ test single_field_expect() {
|
||||||
expect CreateVoteBatch { id } = redeemer
|
expect CreateVoteBatch { id } = redeemer
|
||||||
id == #""
|
id == #""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test single_when() {
|
||||||
|
let redeemer = CreateVoteBatch { id: #"" }
|
||||||
|
let x = when redeemer is {
|
||||||
|
CreateVoteBatch { id } -> id == #""
|
||||||
|
_ -> False
|
||||||
|
}
|
||||||
|
x == True
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue