Skip to content

Commit

Permalink
fix: Fix panic when using repeated arrays which define variables (#3221)
Browse files Browse the repository at this point in the history
  • Loading branch information
jfecher authored Oct 18, 2023
1 parent ad192d1 commit c4faf3a
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
3 changes: 1 addition & 2 deletions compiler/noirc_frontend/src/monomorphization/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ fn main() {
let _ = 42;

let Foo { a: _ } = Foo { a: 42 };
let _regression_2786 = [Foo { a: 1 }; 8];
}

0 comments on commit c4faf3a

Please sign in to comment.