Skip to content

Commit

Permalink
fix: expect _ = ... not including the cast from data logic if the t…
Browse files Browse the repository at this point in the history
…ype is data and right hand has a type annotation
  • Loading branch information
MicroProofs committed Jun 23, 2023
1 parent 226556b commit 8b3504e
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 5 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@

### 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
even if not used.
- **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

Expand Down
21 changes: 18 additions & 3 deletions crates/aiken-lang/src/gen_uplc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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![];
Expand Down
2 changes: 1 addition & 1 deletion examples/acceptance_tests/084/aiken.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name = "aiken-lang/acceptance_test_083"
name = "aiken-lang/acceptance_test_084"
version = "0.0.0"
description = ""

Expand Down
13 changes: 13 additions & 0 deletions examples/acceptance_tests/085/aiken.lock
Original file line number Diff line number Diff line change
@@ -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"
8 changes: 8 additions & 0 deletions examples/acceptance_tests/085/aiken.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
name = "aiken-lang/acceptance_test_085"
version = "0.0.0"
description = ""

[[dependencies]]
name = 'aiken-lang/stdlib'
version = 'main'
source = 'github'
19 changes: 19 additions & 0 deletions examples/acceptance_tests/085/lib/other.ak
Original file line number Diff line number Diff line change
@@ -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,
}
44 changes: 44 additions & 0 deletions examples/acceptance_tests/085/lib/tests.ak
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 8b3504e

Please sign in to comment.