diff --git a/compiler/noirc_frontend/src/elaborator/path_resolution.rs b/compiler/noirc_frontend/src/elaborator/path_resolution.rs index bae5908c31d..4c7bbeeff24 100644 --- a/compiler/noirc_frontend/src/elaborator/path_resolution.rs +++ b/compiler/noirc_frontend/src/elaborator/path_resolution.rs @@ -468,7 +468,11 @@ impl Elaborator<'_> { }); } - let plain_or_crate = matches!(path.kind, PathKind::Plain | PathKind::Crate); + let first_segment_is_always_visible = match path.kind { + PathKind::Crate => true, + PathKind::Plain => importing_module == starting_module, + PathKind::Dep | PathKind::Super | PathKind::Resolved(_) => false, + }; // The current module and module ID as we resolve path segments let mut current_module_id = starting_module; @@ -551,7 +555,7 @@ impl Elaborator<'_> { // If the path is plain or crate, the first segment will always refer to // something that's visible from the current module. - if !((plain_or_crate && index == 0) + if !((first_segment_is_always_visible && index == 0) || item_in_module_is_visible( self.def_maps, importing_module, diff --git a/compiler/noirc_frontend/src/hir/resolution/import.rs b/compiler/noirc_frontend/src/hir/resolution/import.rs index 65a761a8264..4514e07dae9 100644 --- a/compiler/noirc_frontend/src/hir/resolution/import.rs +++ b/compiler/noirc_frontend/src/hir/resolution/import.rs @@ -323,7 +323,11 @@ impl<'def_maps, 'usage_tracker, 'references_tracker> }); } - let plain_or_crate = matches!(path.kind, PathKind::Plain | PathKind::Crate); + let first_segment_is_always_visible = match path.kind { + PathKind::Crate => true, + PathKind::Plain => self.importing_module == starting_module, + PathKind::Dep | PathKind::Super | PathKind::Resolved(_) => false, + }; // The current module and module ID as we resolve path segments let mut current_module_id = starting_module; @@ -375,9 +379,7 @@ impl<'def_maps, 'usage_tracker, 'references_tracker> ModuleDefId::GlobalId(_) => panic!("globals cannot be in the type namespace"), }; - // If the path is plain or crate, the first segment will always refer to - // something that's visible from the current module. - if !((plain_or_crate && index == 0) + if !((first_segment_is_always_visible && index == 0) || self.item_in_module_is_visible(current_module_id, visibility)) { errors.push(PathResolutionError::Private(last_ident.clone())); diff --git a/test_programs/benchmarks/semaphore_depth_10/Nargo.toml b/test_programs/benchmarks/semaphore_depth_10/Nargo.toml index 459bc591f74..eda5c853c4e 100644 --- a/test_programs/benchmarks/semaphore_depth_10/Nargo.toml +++ b/test_programs/benchmarks/semaphore_depth_10/Nargo.toml @@ -4,5 +4,5 @@ type = "bin" authors = [""] [dependencies] -ec = { git = "https://github.com/noir-lang/noir-edwards", tag = "v0.2.4" } +ec = { git = "https://github.com/noir-lang/noir-edwards", tag = "v0.2.5" } poseidon = { git = "https://github.com/noir-lang/poseidon", tag = "v0.1.1" } diff --git a/test_programs/benchmarks/semaphore_depth_10/src/main.nr b/test_programs/benchmarks/semaphore_depth_10/src/main.nr index 1adea28695b..ff46aca0215 100644 --- a/test_programs/benchmarks/semaphore_depth_10/src/main.nr +++ b/test_programs/benchmarks/semaphore_depth_10/src/main.nr @@ -3,9 +3,9 @@ use ec::bjj::BabyJubJubParams; use ec::{Curve, CurveTrait}; -use ec::scalar_field::ScalarField; -use std::field::bn254::assert_lt; +use ec::ScalarField; use poseidon::poseidon::bn254::hash_2 as poseidon; +use std::field::bn254::assert_lt; // The maximum depth of the Merkle Tree the inclusion proof will be coming from. // This value can get updated by overwriting this line. @@ -83,4 +83,4 @@ fn main( // Return the calculated Merkle tree root & nullifier (node, nullifier) -} \ No newline at end of file +} diff --git a/test_programs/compile_failure/access_private_dependency_item/Nargo.toml b/test_programs/compile_failure/access_private_dependency_item/Nargo.toml new file mode 100644 index 00000000000..eba87636939 --- /dev/null +++ b/test_programs/compile_failure/access_private_dependency_item/Nargo.toml @@ -0,0 +1,8 @@ +[package] +name = "access_private_dependency_item" +type = "bin" +authors = [""] +compiler_version = ">=0.33.0" + +[dependencies] +foo = { path = "./foo" } diff --git a/test_programs/compile_failure/access_private_dependency_item/foo/Nargo.toml b/test_programs/compile_failure/access_private_dependency_item/foo/Nargo.toml new file mode 100644 index 00000000000..8d73071b4c6 --- /dev/null +++ b/test_programs/compile_failure/access_private_dependency_item/foo/Nargo.toml @@ -0,0 +1,5 @@ +[package] +name = "foo" +type = "lib" +authors = [""] +compiler_version = ">=0.31.0" diff --git a/test_programs/compile_failure/access_private_dependency_item/foo/src/lib.nr b/test_programs/compile_failure/access_private_dependency_item/foo/src/lib.nr new file mode 100644 index 00000000000..90b6006774d --- /dev/null +++ b/test_programs/compile_failure/access_private_dependency_item/foo/src/lib.nr @@ -0,0 +1,3 @@ +mod bar { + pub fn baz() {} +} diff --git a/test_programs/compile_failure/access_private_dependency_item/src/main.nr b/test_programs/compile_failure/access_private_dependency_item/src/main.nr new file mode 100644 index 00000000000..53b8b6e75e2 --- /dev/null +++ b/test_programs/compile_failure/access_private_dependency_item/src/main.nr @@ -0,0 +1,6 @@ +use foo::bar::baz; + +fn main() { + foo::bar::baz(); + baz(); +} diff --git a/tooling/nargo_cli/tests/snapshots/compile_failure/access_private_dependency_item/execute__tests__stderr.snap b/tooling/nargo_cli/tests/snapshots/compile_failure/access_private_dependency_item/execute__tests__stderr.snap new file mode 100644 index 00000000000..4aa95b1673b --- /dev/null +++ b/tooling/nargo_cli/tests/snapshots/compile_failure/access_private_dependency_item/execute__tests__stderr.snap @@ -0,0 +1,19 @@ +--- +source: tooling/nargo_cli/tests/execute.rs +expression: stderr +--- +error: bar is private and not visible from the current module + ┌─ src/main.nr:1:10 + │ +1 │ use foo::bar::baz; + │ --- bar is private + │ + +error: bar is private and not visible from the current module + ┌─ src/main.nr:4:10 + │ +4 │ foo::bar::baz(); + │ --- bar is private + │ + +Aborting due to 2 previous errors