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: set local_module before elaborating each trait #6506

Merged
merged 1 commit into from
Nov 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
2 changes: 2 additions & 0 deletions compiler/noirc_frontend/src/elaborator/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ use super::Elaborator;
impl<'context> Elaborator<'context> {
pub fn collect_traits(&mut self, traits: &BTreeMap<TraitId, UnresolvedTrait>) {
for (trait_id, unresolved_trait) in traits {
self.local_module = unresolved_trait.module_id;

self.recover_generics(|this| {
this.current_trait = Some(*trait_id);

Expand Down
20 changes: 20 additions & 0 deletions compiler/noirc_frontend/src/tests/unused_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,3 +294,23 @@ fn no_warning_on_self_in_trait_impl() {
"#;
assert_no_errors(src);
}

#[test]
fn resolves_trait_where_clause_in_the_correct_module() {
// This is a regression test for https://github.com/noir-lang/noir/issues/6479
let src = r#"
mod foo {
pub trait Foo {}
}

use foo::Foo;

pub trait Bar<T>
where
T: Foo,
{}

fn main() {}
"#;
assert_no_errors(src);
}
Loading