Skip to content

Commit

Permalink
fix: set local_module before elaborating each trait (#6506)
Browse files Browse the repository at this point in the history
  • Loading branch information
asterite authored Nov 12, 2024
1 parent 34ad666 commit 1df8c45
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
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);
}

0 comments on commit 1df8c45

Please sign in to comment.