diff --git a/CHANGELOG.md b/CHANGELOG.md index 7541f296..43f00243 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ ### Fixed +- **aiken-lang**: Fix expect _ = ... not including the cast from data logic if the type is data and right hand has a type annotation - **aiken-lang**: Fix for the final clause of a when expecting another clause afterwards in nested list cases. - **aiken-lang**: Fix for all elements were being destructured in tuple clauses @@ -22,7 +23,8 @@ - **aiken-lang**: Fix for tuple clause not consuming the next case causing incomplete contracts. Now tuple clause will always consume the next case unless it is the final clause - - **aiken-lang**: Fix for builtins using the incorrect data to type conversion when used as a function param. + - **aiken-lang**: Fix for builtins using the incorrect data to type conversion + when used as a function param. ## v1.0.10-alpha - 2023-06-13 diff --git a/crates/aiken-lang/src/gen_uplc.rs b/crates/aiken-lang/src/gen_uplc.rs index 68e0709f..2791b22c 100644 --- a/crates/aiken-lang/src/gen_uplc.rs +++ b/crates/aiken-lang/src/gen_uplc.rs @@ -1701,7 +1701,7 @@ impl<'a> CodeGenerator<'a> { ) { let mut value_stack = if assignment_properties.value_type.is_data() && !tipo.is_data() - && !pattern.is_discard() + && matches!(assignment_properties.kind, AssignmentKind::Expect) { let mut wrap_stack = pattern_stack.empty_with_scope(); wrap_stack.un_wrap_data(tipo.clone().into()); @@ -1765,7 +1765,17 @@ impl<'a> CodeGenerator<'a> { ); } Pattern::Discard { .. } => { - pattern_stack.let_assignment("_", value_stack); + if matches!(assignment_properties.kind, AssignmentKind::Let) { + pattern_stack.let_assignment("_", value_stack); + } else { + self.expect_pattern( + pattern, + pattern_stack, + value_stack, + tipo, + assignment_properties, + ) + } } list @ Pattern::List { .. } => { if matches!(assignment_properties.kind, AssignmentKind::Expect) @@ -2097,7 +2107,12 @@ impl<'a> CodeGenerator<'a> { self.expect_type(tipo, expect_stack, name, &mut IndexMap::new()); } Pattern::Assign { .. } => todo!("Expect Assign not supported yet"), - Pattern::Discard { .. } => unreachable!(), + Pattern::Discard { .. } => { + let name = "__expect_discard"; + + expect_stack.let_assignment(name, value_stack); + self.expect_type(tipo, expect_stack, name, &mut IndexMap::new()); + } Pattern::List { elements, tail, .. } => { let inner_list_type = &tipo.get_inner_types()[0]; let mut names = vec![]; diff --git a/examples/acceptance_tests/084/aiken.toml b/examples/acceptance_tests/084/aiken.toml index 1d26e775..dce5f766 100644 --- a/examples/acceptance_tests/084/aiken.toml +++ b/examples/acceptance_tests/084/aiken.toml @@ -1,4 +1,4 @@ -name = "aiken-lang/acceptance_test_083" +name = "aiken-lang/acceptance_test_084" version = "0.0.0" description = "" diff --git a/examples/acceptance_tests/085/aiken.lock b/examples/acceptance_tests/085/aiken.lock new file mode 100644 index 00000000..0423f31b --- /dev/null +++ b/examples/acceptance_tests/085/aiken.lock @@ -0,0 +1,13 @@ +# This file was generated by Aiken +# You typically do not need to edit this file + +[[requirements]] +name = "aiken-lang/stdlib" +version = "main" +source = "github" + +[[packages]] +name = "aiken-lang/stdlib" +version = "main" +requirements = [] +source = "github" diff --git a/examples/acceptance_tests/085/aiken.toml b/examples/acceptance_tests/085/aiken.toml new file mode 100644 index 00000000..7e9bdd0b --- /dev/null +++ b/examples/acceptance_tests/085/aiken.toml @@ -0,0 +1,8 @@ +name = "aiken-lang/acceptance_test_085" +version = "0.0.0" +description = "" + +[[dependencies]] +name = 'aiken-lang/stdlib' +version = 'main' +source = 'github' diff --git a/examples/acceptance_tests/085/lib/other.ak b/examples/acceptance_tests/085/lib/other.ak new file mode 100644 index 00000000..0551bc4e --- /dev/null +++ b/examples/acceptance_tests/085/lib/other.ak @@ -0,0 +1,19 @@ +pub type AssetClass { + policy: ByteArray, + name: ByteArray, +} + +pub type DatumOrc { + oracle_parameters: OracleParametersd, + token_a_amount: Int, + token_b_amount: Int, + expiration_time: Int, + maturity_time: Int, +} + +pub type OracleParametersd { + pool_nft_cs: AssetClass, + oracle_nft_cs: AssetClass, + token_a_cs: AssetClass, + token_b_cs: AssetClass, +} diff --git a/examples/acceptance_tests/085/lib/tests.ak b/examples/acceptance_tests/085/lib/tests.ak new file mode 100644 index 00000000..9b4cc2e6 --- /dev/null +++ b/examples/acceptance_tests/085/lib/tests.ak @@ -0,0 +1,44 @@ +use other + +pub type AssetClass { + policy: ByteArray, + name: ByteArray, +} + +pub type DatumOrc1 { + oracle_parameters: OracleParametersd, + token_a_amount: Int, + token_b_amount: Int, + expiration_time: Int, + maturity_time: Int, +} + +pub type OracleParametersd { + pool_nft_cs: AssetClass, + oracle_nft_cs: AssetClass, + token_a_cs: AssetClass, + token_b_cs: AssetClass, +} + +test oracle1() { + let x: Data = + DatumOrc1 { + oracle_parameters: OracleParametersd { + pool_nft_cs: AssetClass { policy: #"", name: #"" }, + oracle_nft_cs: AssetClass { policy: #"", name: #"" }, + token_a_cs: AssetClass { policy: #"", name: #"" }, + token_b_cs: AssetClass { policy: #"", name: #"" }, + }, + token_a_amount: 0, + token_b_amount: 0, + expiration_time: 0, + maturity_time: 0, + } + + let y: Data = x + + expect _: other.DatumOrc = y + + // od == od + True +}