From 62252eb1cf7f0714226be3acaf0d484c00515f7c Mon Sep 17 00:00:00 2001 From: Tom French Date: Wed, 30 Oct 2024 12:38:50 +0000 Subject: [PATCH] chore: add regression tests for #4372 --- compiler/noirc_frontend/src/tests.rs | 26 ++++++++++++++------ compiler/noirc_frontend/src/tests/aliases.rs | 16 ++++++++++++ 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/compiler/noirc_frontend/src/tests.rs b/compiler/noirc_frontend/src/tests.rs index 56c4b5e9a12..25a5af64ccb 100644 --- a/compiler/noirc_frontend/src/tests.rs +++ b/compiler/noirc_frontend/src/tests.rs @@ -3548,17 +3548,27 @@ fn uses_self_in_import() { } #[test] -fn alias_in_let_pattern() { +fn does_not_error_on_return_values_after_block_expression() { + // Regression test for https://github.com/noir-lang/noir/issues/4372 let src = r#" - struct Foo { x: T } - - type Bar = Foo; + fn case1() -> [Field] { + if true { + } + &[1] + } - fn main() { - let Bar { x } = Foo { x: [0] }; - // This is just to show the compiler knows this is an array. - let _: [Field; 1] = x; + fn case2() -> [u8] { + let mut var: u8 = 1; + { + var += 1; } + &[var] + } + + fn main() { + let _ = case1(); + let _ = case2(); + } "#; assert_no_errors(src); } diff --git a/compiler/noirc_frontend/src/tests/aliases.rs b/compiler/noirc_frontend/src/tests/aliases.rs index 5239abcb366..8d3433299f6 100644 --- a/compiler/noirc_frontend/src/tests/aliases.rs +++ b/compiler/noirc_frontend/src/tests/aliases.rs @@ -31,3 +31,19 @@ fn allows_usage_of_type_alias_as_return_type() { "#; assert_no_errors(src); } + +#[test] +fn alias_in_let_pattern() { + let src = r#" + struct Foo { x: T } + + type Bar = Foo; + + fn main() { + let Bar { x } = Foo { x: [0] }; + // This is just to show the compiler knows this is an array. + let _: [Field; 1] = x; + } + "#; + assert_no_errors(src); +}