diff --git a/lib/src/compiler/mod.rs b/lib/src/compiler/mod.rs index 0f041ce4..8dddd463 100644 --- a/lib/src/compiler/mod.rs +++ b/lib/src/compiler/mod.rs @@ -1432,18 +1432,6 @@ impl<'a> Compiler<'a> { // Yes, module exists. let module = module.unwrap(); - // Is the module banned? If yes, produce an error. - if let Some((error_title, error_msg)) = - self.banned_modules.get(module_name) - { - return Err(CustomError::build( - &self.report_builder, - error_title.clone(), - error_msg.clone(), - import.span().into(), - )); - } - // If the module has not been added to `self.root_struct` and // `self.imported_modules`, do it. if !self.root_struct.has_field(module_name) { @@ -1504,6 +1492,21 @@ impl<'a> Compiler<'a> { ); } + // Is the module banned? If yes, produce an error. Notice however that + // this check is done after the module has been added to the symbol + // table because we don't want additional errors due to undefined + // identifiers when the banned module is used in some rule condition. + if let Some((error_title, error_msg)) = + self.banned_modules.get(module_name) + { + return Err(CustomError::build( + &self.report_builder, + error_title.clone(), + error_msg.clone(), + import.span().into(), + )); + } + Ok(()) } diff --git a/lib/src/compiler/tests/mod.rs b/lib/src/compiler/tests/mod.rs index f78fe3e7..1dc96238 100644 --- a/lib/src/compiler/tests/mod.rs +++ b/lib/src/compiler/tests/mod.rs @@ -595,6 +595,7 @@ fn banned_modules() { .add_source( r#" import "test_proto2" + rule test { condition: test_proto2.int32_zero == 0} "#, ) .expect_err("expected error") @@ -606,6 +607,11 @@ fn banned_modules() { | ^^^^^^^^^^^^^^^^^^^^ module `test_proto2` is used here |"# ); + + // The only error should be the error about the use of a banned module, + // the condition `test_proto2.int32_zero == 0` should not produce any + // error. + assert_eq!(compiler.errors().len(), 1); } #[cfg(feature = "test_proto2-module")]