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(frontend): Do not warn when a nested struct is provided as input to main #6239

Merged
merged 2 commits into from
Oct 8, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions compiler/noirc_frontend/src/elaborator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,9 @@ impl<'context> Elaborator<'context> {
for generic in generics {
self.mark_parameter_type_as_used(generic);
}
for (_, typ) in struct_type.borrow().get_fields(generics) {
self.mark_parameter_type_as_used(&typ);
}
}
Type::Alias(alias_type, generics) => {
self.mark_parameter_type_as_used(&alias_type.borrow().get_type(generics));
Expand All @@ -872,15 +875,6 @@ impl<'context> Elaborator<'context> {
| Type::Forall(..)
| Type::Error => (),
}

if let Type::Alias(alias_type, generics) = typ {
self.mark_parameter_type_as_used(&alias_type.borrow().get_type(generics));
return;
}

if let Type::Struct(struct_type, _generics) = typ {
vezenovm marked this conversation as resolved.
Show resolved Hide resolved
self.mark_struct_as_constructed(struct_type.clone());
}
}

fn run_function_lints(&mut self, func: &FuncMeta, modifiers: &FunctionModifiers) {
Expand Down
21 changes: 21 additions & 0 deletions compiler/noirc_frontend/src/tests/unused_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,3 +210,24 @@ fn warns_on_unused_global() {
assert_eq!(ident.to_string(), "foo");
assert_eq!(item.item_type(), "global");
}

#[test]
fn no_warning_on_inner_struct_when_parent_is_used() {
let src = r#"
struct Bar {
inner: [Field; 3],
}

struct Foo {
a: Field,
bar: Bar,
}

fn main(foos: [Foo; 1]) {
assert_eq(foos[0].a, 10);
}
"#;

let errors = get_program_errors(src);
assert_eq!(errors.len(), 0);
}
Loading