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: Allow non-integer globals to reference struct methods #4490

Merged
merged 2 commits into from
Mar 12, 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
10 changes: 5 additions & 5 deletions compiler/noirc_frontend/src/hir/def_collector/dc_crate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,11 +331,6 @@ impl DefCollector {
// Must resolve structs before we resolve globals.
errors.extend(resolve_structs(context, def_collector.collected_types, crate_id));

// We must wait to resolve non-integer globals until after we resolve structs since struct
// globals will need to reference the struct type they're initialized to to ensure they are valid.
resolved_globals.extend(resolve_globals(context, other_globals, crate_id));
errors.extend(resolved_globals.errors);

// Bind trait impls to their trait. Collect trait functions, that have a
// default implementation, which hasn't been overridden.
errors.extend(collect_trait_impls(
Expand All @@ -353,6 +348,11 @@ impl DefCollector {
// over trait methods if there are name conflicts.
errors.extend(collect_impls(context, crate_id, &def_collector.collected_impls));

// We must wait to resolve non-integer globals until after we resolve structs since struct
// globals will need to reference the struct type they're initialized to to ensure they are valid.
resolved_globals.extend(resolve_globals(context, other_globals, crate_id));
errors.extend(resolved_globals.errors);

// Resolve each function in the crate. This is now possible since imports have been resolved
let mut functions = Vec::new();
functions.extend(resolve_free_functions(
Expand Down
17 changes: 17 additions & 0 deletions test_programs/execution_success/global_consts/src/main.nr
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,20 @@ mod my_submodule {
x
}
}

struct Foo {
a: Field,
}

struct Bar {}

impl Bar {
fn get_a() -> Field {
1
}
}

// Regression for #1440
global foo = Foo {
a: Bar::get_a(),
};
Loading