Skip to content
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
9 changes: 7 additions & 2 deletions compiler/noirc_frontend/src/elaborator/comptime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,9 +377,11 @@ impl<'context> Elaborator<'context> {
location: Location,
generated_items: &mut CollectedItems,
) -> Result<(), CompilationError> {
self.local_module = Some(attribute_context.module);
// Arguments must be resolved relative to the module where the attribute happens
self.local_module = Some(attribute_context.attribute_module);

let mut interpreter = self.setup_interpreter();

let mut arguments = Self::handle_attribute_arguments(
&mut interpreter,
&item,
Expand All @@ -398,9 +400,12 @@ impl<'context> Elaborator<'context> {
self.debug_comptime(location, |interner| value.display(interner).to_string());

if value != Value::Unit {
// Items must be added in the correct module (for a module attribute, this will be the
// module itself; for a function, it will be the module where the function is defined, etc.)
self.local_module = Some(attribute_context.module);

let items =
value.into_top_level_items(location, self).map_err(CompilationError::from)?;

self.add_items(items, generated_items, location);
}

Expand Down
28 changes: 28 additions & 0 deletions compiler/noirc_frontend/src/tests/metaprogramming.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1490,3 +1490,31 @@ fn unifies_macro_call_type_with_variable_type_in_comptime_block() {
"#;
assert_no_errors(src);
}

// Regression test for https://github.com/noir-lang/noir/issues/11575
#[test]
fn path_inside_module_attribute() {
let src = r#"
pub mod one {
pub comptime fn attr(_: Module, _: Config) {}

pub struct Config {}

impl Config {
pub fn new() -> Self {
Self {}
}
}
}

use one::{attr, Config};

#[attr(Config::new())]
mod coco {}

pub fn main() {
let _ = Config::new();
}
"#;
assert_no_errors(src);
}
Loading