Skip to content
Merged
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
51 changes: 48 additions & 3 deletions compiler/noirc_frontend/src/tests/metaprogramming.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
use crate::hir::{
def_collector::dc_crate::CompilationError, resolution::errors::ResolverError,
type_check::TypeCheckError,
use noirc_errors::Spanned;

use crate::{
ast::Ident,
hir::{
def_collector::{
dc_crate::CompilationError,
errors::{DefCollectorErrorKind, DuplicateType},
},
resolution::errors::ResolverError,
type_check::TypeCheckError,
},
};

use super::{assert_no_errors, get_program_errors};
Expand Down Expand Up @@ -96,3 +105,39 @@ fn allows_references_to_structs_generated_by_macros() {

assert_no_errors(src);
}

#[test]
fn errors_if_macros_inject_functions_with_name_collisions() {
let src = r#"
comptime fn make_colliding_functions(_s: StructDefinition) -> Quoted {
quote {
fn foo() {}
}
}

#[make_colliding_functions]
struct Foo {}

#[make_colliding_functions]
struct Bar {}

fn main() {
let _ = Foo {};
let _ = Bar {};
foo();
}
"#;

let errors = get_program_errors(src);
assert_eq!(errors.len(), 1);
assert!(matches!(
&errors[0].0,
CompilationError::DefinitionError(
DefCollectorErrorKind::Duplicate {
typ: DuplicateType::Function,
first_def: Ident(Spanned { contents, .. }),
..
},
) if contents == "foo"
));
}