Fix opaque type destructuring in code gen
This commit is contained in:
parent
1edd1a1fa3
commit
ae396c0224
|
@ -250,7 +250,7 @@ impl<'a> CodeGenerator<'a> {
|
||||||
panic!("Dangling expressions without an assignment")
|
panic!("Dangling expressions without an assignment")
|
||||||
};
|
};
|
||||||
|
|
||||||
let replaced_type = convert_opaque_type(tipo, &self.data_types, true);
|
// let replaced_type = convert_opaque_type(tipo, &self.data_types, true);
|
||||||
|
|
||||||
let air_value = self.build(value, module_build_name, &[]);
|
let air_value = self.build(value, module_build_name, &[]);
|
||||||
|
|
||||||
|
@ -294,7 +294,7 @@ impl<'a> CodeGenerator<'a> {
|
||||||
pattern,
|
pattern,
|
||||||
air_value,
|
air_value,
|
||||||
then,
|
then,
|
||||||
&replaced_type,
|
tipo,
|
||||||
AssignmentProperties {
|
AssignmentProperties {
|
||||||
value_type: value.tipo(),
|
value_type: value.tipo(),
|
||||||
kind: *kind,
|
kind: *kind,
|
||||||
|
@ -1200,6 +1200,7 @@ impl<'a> CodeGenerator<'a> {
|
||||||
// TODO: See if we can combine these two if-conditions;
|
// TODO: See if we can combine these two if-conditions;
|
||||||
//
|
//
|
||||||
// i.e. can we lift data_type assignment out of the first if?
|
// i.e. can we lift data_type assignment out of the first if?
|
||||||
|
|
||||||
let then = if props.kind.is_expect() {
|
let then = if props.kind.is_expect() {
|
||||||
let data_type = lookup_data_type_by_tipo(&self.data_types, tipo)
|
let data_type = lookup_data_type_by_tipo(&self.data_types, tipo)
|
||||||
.unwrap_or_else(|| {
|
.unwrap_or_else(|| {
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
# This file was generated by Aiken
|
||||||
|
# You typically do not need to edit this file
|
||||||
|
|
||||||
|
requirements = []
|
||||||
|
packages = []
|
||||||
|
|
||||||
|
[etags]
|
|
@ -0,0 +1,3 @@
|
||||||
|
name = "aiken-lang/acceptance_test_097"
|
||||||
|
version = "0.0.0"
|
||||||
|
description = ""
|
|
@ -0,0 +1,24 @@
|
||||||
|
pub opaque type Dict<a, b> {
|
||||||
|
inner: List<(a, b)>,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub opaque type Value {
|
||||||
|
inner: Dict<ByteArray, Dict<ByteArray, Int>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn to_dict(v: Value) {
|
||||||
|
v.inner
|
||||||
|
}
|
||||||
|
|
||||||
|
fn to_list(d: Dict<a, b>) {
|
||||||
|
d.inner
|
||||||
|
}
|
||||||
|
|
||||||
|
test opaque_destructure() {
|
||||||
|
let x = Value { inner: Dict { inner: [(#"", Dict { inner: [("ab", 3)] })] } }
|
||||||
|
|
||||||
|
expect [(policy_a, Dict{inner: [(asset_name_a, quantity_a), ..]}), ..] =
|
||||||
|
x |> to_dict() |> to_list()
|
||||||
|
|
||||||
|
quantity_a > 2
|
||||||
|
}
|
Loading…
Reference in New Issue