From 9f0b3971ee41e78241cbea4e3f81bac4edd5897d Mon Sep 17 00:00:00 2001 From: Ary Borenszweig Date: Mon, 23 Sep 2024 16:09:28 -0300 Subject: [PATCH] fix: handle parenthesized expressions in array length (#6132) # Description ## Problem We were missing handling parenthesized expressions in `UnresolvedTypeExpression::from_expr_helper` ## Summary Fixes the above issue. ## Additional Context ## Documentation Check one: - [x] No documentation needed. - [ ] Documentation included in this PR. - [ ] **[For Experimental Features]** Documentation to be submitted in a separate PR. # PR Checklist - [x] I have tested the changes locally. - [x] I have formatted the changes with [Prettier](https://prettier.io/) and/or `cargo fmt` on default settings. --- compiler/noirc_frontend/src/ast/mod.rs | 1 + .../parenthesized_expression_in_array_length/Nargo.toml | 7 +++++++ .../parenthesized_expression_in_array_length/src/main.nr | 6 ++++++ 3 files changed, 14 insertions(+) create mode 100644 test_programs/compile_success_empty/parenthesized_expression_in_array_length/Nargo.toml create mode 100644 test_programs/compile_success_empty/parenthesized_expression_in_array_length/src/main.nr diff --git a/compiler/noirc_frontend/src/ast/mod.rs b/compiler/noirc_frontend/src/ast/mod.rs index fe9153c2cf4..94e81b19582 100644 --- a/compiler/noirc_frontend/src/ast/mod.rs +++ b/compiler/noirc_frontend/src/ast/mod.rs @@ -460,6 +460,7 @@ impl UnresolvedTypeExpression { ExpressionKind::AsTraitPath(path) => { Ok(UnresolvedTypeExpression::AsTraitPath(Box::new(path))) } + ExpressionKind::Parenthesized(expr) => Self::from_expr_helper(*expr), _ => Err(expr), } } diff --git a/test_programs/compile_success_empty/parenthesized_expression_in_array_length/Nargo.toml b/test_programs/compile_success_empty/parenthesized_expression_in_array_length/Nargo.toml new file mode 100644 index 00000000000..e56e9643f40 --- /dev/null +++ b/test_programs/compile_success_empty/parenthesized_expression_in_array_length/Nargo.toml @@ -0,0 +1,7 @@ +[package] +name = "parenthesized_expression_in_array_length" +type = "bin" +authors = [""] +compiler_version = ">=0.32.0" + +[dependencies] \ No newline at end of file diff --git a/test_programs/compile_success_empty/parenthesized_expression_in_array_length/src/main.nr b/test_programs/compile_success_empty/parenthesized_expression_in_array_length/src/main.nr new file mode 100644 index 00000000000..b596d331e7f --- /dev/null +++ b/test_programs/compile_success_empty/parenthesized_expression_in_array_length/src/main.nr @@ -0,0 +1,6 @@ +global N = 100; +global BLOCK_SIZE = 10; + +fn main() { + let _: [Field; 110] = [0; ((N + BLOCK_SIZE) * BLOCK_SIZE) / BLOCK_SIZE]; +}