Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Substitute generics when checking the field count of a type #4547

Merged
merged 2 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 1 addition & 5 deletions compiler/noirc_frontend/src/hir_def/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,7 @@
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())
}
Expand Down Expand Up @@ -1526,7 +1522,7 @@
Type::Tuple(fields)
}
Type::Forall(typevars, typ) => {
// Trying to substitute_helper a variable de, substitute_bound_typevarsfined within a nested Forall

Check warning on line 1525 in compiler/noirc_frontend/src/hir_def/types.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (typevarsfined)
// is usually impossible and indicative of an error in the type checker somewhere.
for var in typevars {
assert!(!type_bindings.contains_key(&var.id()));
Expand Down
10 changes: 10 additions & 0 deletions compiler/noirc_frontend/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<N> = [u8; N];
fn main(_arg: Outer<1>) {}
"#;
assert_eq!(get_program_errors(src).len(), 0);
}
}