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]; }