From 2170c1ddbec8beb77fafaae2ed14408f9c940f73 Mon Sep 17 00:00:00 2001 From: Jake Fecher Date: Wed, 13 Mar 2024 12:04:36 -0500 Subject: [PATCH 1/2] Fix 4545 --- compiler/noirc_frontend/src/hir_def/types.rs | 6 +----- compiler/noirc_frontend/src/tests.rs | 10 ++++++++++ 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/compiler/noirc_frontend/src/hir_def/types.rs b/compiler/noirc_frontend/src/hir_def/types.rs index 5ab036eef5b..60bc5b2470f 100644 --- a/compiler/noirc_frontend/src/hir_def/types.rs +++ b/compiler/noirc_frontend/src/hir_def/types.rs @@ -127,11 +127,7 @@ impl Type { let fields = struct_type.get_fields(args); fields.iter().fold(0, |acc, (_, field_type)| acc + field_type.field_count()) } - Type::Alias(def, _) => { - // It is safe to access `typ` without instantiating generics here since generics - // cannot change the number of fields in `typ`. - def.borrow().typ.field_count() - } + Type::Alias(def, generics) => def.borrow().get_type(generics).field_count(), Type::Tuple(fields) => { fields.iter().fold(0, |acc, field_typ| acc + field_typ.field_count()) } diff --git a/compiler/noirc_frontend/src/tests.rs b/compiler/noirc_frontend/src/tests.rs index 3f78bd43ba9..de49095d69e 100644 --- a/compiler/noirc_frontend/src/tests.rs +++ b/compiler/noirc_frontend/src/tests.rs @@ -1213,4 +1213,14 @@ fn lambda$f1(mut env$l1: (Field)) -> Field { "#; assert_eq!(get_program_errors(src).len(), 0); } + + // Regression for #4545 + #[test] + fn type_aliases_in_main() { + let src = r#" + type Outer = [u8; N]; + fn main(arg: Outer<1>) {} + "#; + assert_eq!(get_program_errors(src).len(), 0); + } } From ffd7344e4091139e2136ec491b68d68cee2e7e88 Mon Sep 17 00:00:00 2001 From: Jake Fecher Date: Wed, 13 Mar 2024 12:18:12 -0500 Subject: [PATCH 2/2] Fix unused parameter --- compiler/noirc_frontend/src/tests.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/noirc_frontend/src/tests.rs b/compiler/noirc_frontend/src/tests.rs index de49095d69e..1158f4c229a 100644 --- a/compiler/noirc_frontend/src/tests.rs +++ b/compiler/noirc_frontend/src/tests.rs @@ -1219,7 +1219,7 @@ fn lambda$f1(mut env$l1: (Field)) -> Field { fn type_aliases_in_main() { let src = r#" type Outer = [u8; N]; - fn main(arg: Outer<1>) {} + fn main(_arg: Outer<1>) {} "#; assert_eq!(get_program_errors(src).len(), 0); }