From b27fcf38e53cff280c364c356ccbeb8cd7d73caf Mon Sep 17 00:00:00 2001 From: rvcas Date: Tue, 2 Apr 2024 19:45:16 -0400 Subject: [PATCH] fix(check): collapse_links on tuple_index access closes #905 --- crates/aiken-lang/src/tests/check.rs | 21 +++++++++++++++++++++ crates/aiken-lang/src/tipo/expr.rs | 2 +- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/crates/aiken-lang/src/tests/check.rs b/crates/aiken-lang/src/tests/check.rs index 865f83f0..a188efc4 100644 --- a/crates/aiken-lang/src/tests/check.rs +++ b/crates/aiken-lang/src/tests/check.rs @@ -2274,3 +2274,24 @@ fn validator_private_everything() { assert!(check_validator(parse(source_code)).is_ok()) } + +#[test] +fn tuple_access_on_call() { + let source_code = r#" + use aiken/builtin + + pub fn list_at(xs: List, index: Int) -> a { + if index == 0 { + builtin.head_list(xs) + } else { + list_at(builtin.tail_list(xs), index - 1) + } + } + + fn foo() { + [list_at([(1, 2)], 0).2nd, ..[1, 2]] + } + "#; + + assert!(check(parse(source_code)).is_ok()) +} diff --git a/crates/aiken-lang/src/tipo/expr.rs b/crates/aiken-lang/src/tipo/expr.rs index 8875506a..7aa932f9 100644 --- a/crates/aiken-lang/src/tipo/expr.rs +++ b/crates/aiken-lang/src/tipo/expr.rs @@ -2045,7 +2045,7 @@ impl<'a, 'b> ExprTyper<'a, 'b> { ) -> Result { let tuple = self.infer(tuple)?; - let tipo = match *tuple.tipo() { + let tipo = match *collapse_links(tuple.tipo()) { Type::Tuple { ref elems, alias: _,