From c4faf3a0a40eea1ee02e11dfe08b48c6b4438bbf Mon Sep 17 00:00:00 2001 From: jfecher Date: Wed, 18 Oct 2023 14:59:47 -0500 Subject: [PATCH] fix: Fix panic when using repeated arrays which define variables (#3221) --- compiler/noirc_frontend/src/monomorphization/mod.rs | 3 +-- .../nargo_cli/tests/compile_success_empty/let_stmt/src/main.nr | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/noirc_frontend/src/monomorphization/mod.rs b/compiler/noirc_frontend/src/monomorphization/mod.rs index 39250be619a..764159a4df3 100644 --- a/compiler/noirc_frontend/src/monomorphization/mod.rs +++ b/compiler/noirc_frontend/src/monomorphization/mod.rs @@ -412,12 +412,11 @@ impl<'interner> Monomorphizer<'interner> { ) -> ast::Expression { let typ = self.convert_type(&self.interner.id_type(array)); - let contents = self.expr(repeated_element); let length = length .evaluate_to_u64() .expect("Length of array is unknown when evaluating numeric generic"); - let contents = vec![contents; length as usize]; + let contents = vecmap(0..length, |_| self.expr(repeated_element)); ast::Expression::Literal(ast::Literal::Array(ast::ArrayLiteral { contents, typ })) } diff --git a/tooling/nargo_cli/tests/compile_success_empty/let_stmt/src/main.nr b/tooling/nargo_cli/tests/compile_success_empty/let_stmt/src/main.nr index d24a77851e4..6c63ecd6e12 100644 --- a/tooling/nargo_cli/tests/compile_success_empty/let_stmt/src/main.nr +++ b/tooling/nargo_cli/tests/compile_success_empty/let_stmt/src/main.nr @@ -7,4 +7,5 @@ fn main() { let _ = 42; let Foo { a: _ } = Foo { a: 42 }; + let _regression_2786 = [Foo { a: 1 }; 8]; }