Skip to content

Commit

Permalink
chore: add test to check that duplicate definitions generated from ma…
Browse files Browse the repository at this point in the history
…cros throws error
  • Loading branch information
TomAFrench committed Oct 25, 2024
1 parent d8e549a commit acab0d9
Showing 1 changed file with 48 additions and 3 deletions.
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"
));
}

0 comments on commit acab0d9

Please sign in to comment.