forked from noir-lang/noir
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: visibility for modules (noir-lang#6165)
# Description ## Problem Part of noir-lang#4515 ## Summary ## Additional Context I made most of the stdlib modules public. These are all except the test modules and some modules that I thought were just implementation details of some other modules. I'm adding very short documentation for each of these. I'm thinking that once we get all visibility done it should be documented in its own section, with examples. ## Documentation Check one: - [ ] No documentation needed. - [x] Documentation included in this PR. - [ ] **[For Experimental Features]** Documentation to be submitted in a separate PR. # PR Checklist - [x] I have tested the changes locally. - [x] I have formatted the changes with [Prettier](https://prettier.io/) and/or `cargo fmt` on default settings. --------- Co-authored-by: Tom French <15848336+TomAFrench@users.noreply.github.com>
- Loading branch information
1 parent
877b806
commit fcdbcb9
Showing
27 changed files
with
260 additions
and
185 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
use crate::{ | ||
hir::{ | ||
def_collector::{dc_crate::CompilationError, errors::DefCollectorErrorKind}, | ||
resolution::{errors::ResolverError, import::PathResolutionError}, | ||
}, | ||
tests::get_program_errors, | ||
}; | ||
|
||
#[test] | ||
fn errors_once_on_unused_import_that_is_not_accessible() { | ||
// Tests that we don't get an "unused import" here given that the import is not accessible | ||
let src = r#" | ||
mod moo { | ||
struct Foo {} | ||
} | ||
use moo::Foo; | ||
fn main() { | ||
let _ = Foo {}; | ||
} | ||
"#; | ||
|
||
let errors = get_program_errors(src); | ||
assert_eq!(errors.len(), 1); | ||
assert!(matches!( | ||
errors[0].0, | ||
CompilationError::DefinitionError(DefCollectorErrorKind::PathResolutionError( | ||
PathResolutionError::Private { .. } | ||
)) | ||
)); | ||
} | ||
|
||
#[test] | ||
fn errors_if_type_alias_aliases_more_private_type() { | ||
let src = r#" | ||
struct Foo {} | ||
pub type Bar = Foo; | ||
pub fn no_unused_warnings(_b: Bar) { | ||
let _ = Foo {}; | ||
} | ||
fn main() {} | ||
"#; | ||
|
||
let errors = get_program_errors(src); | ||
assert_eq!(errors.len(), 1); | ||
|
||
let CompilationError::ResolverError(ResolverError::TypeIsMorePrivateThenItem { | ||
typ, item, .. | ||
}) = &errors[0].0 | ||
else { | ||
panic!("Expected an unused item error"); | ||
}; | ||
|
||
assert_eq!(typ, "Foo"); | ||
assert_eq!(item, "Bar"); | ||
} | ||
|
||
#[test] | ||
fn errors_if_type_alias_aliases_more_private_type_in_generic() { | ||
let src = r#" | ||
pub struct Generic<T> { value: T } | ||
struct Foo {} | ||
pub type Bar = Generic<Foo>; | ||
pub fn no_unused_warnings(_b: Bar) { | ||
let _ = Foo {}; | ||
let _ = Generic { value: 1 }; | ||
} | ||
fn main() {} | ||
"#; | ||
|
||
let errors = get_program_errors(src); | ||
assert_eq!(errors.len(), 1); | ||
|
||
let CompilationError::ResolverError(ResolverError::TypeIsMorePrivateThenItem { | ||
typ, item, .. | ||
}) = &errors[0].0 | ||
else { | ||
panic!("Expected an unused item error"); | ||
}; | ||
|
||
assert_eq!(typ, "Foo"); | ||
assert_eq!(item, "Bar"); | ||
} | ||
|
||
#[test] | ||
fn errors_if_trying_to_access_public_function_inside_private_module() { | ||
let src = r#" | ||
mod foo { | ||
mod bar { | ||
pub fn baz() {} | ||
} | ||
} | ||
fn main() { | ||
foo::bar::baz() | ||
} | ||
"#; | ||
|
||
let errors = get_program_errors(src); | ||
assert_eq!(errors.len(), 2); // There's a bug that duplicates this error | ||
|
||
let CompilationError::ResolverError(ResolverError::PathResolutionError( | ||
PathResolutionError::Private(ident), | ||
)) = &errors[0].0 | ||
else { | ||
panic!("Expected a private error"); | ||
}; | ||
|
||
assert_eq!(ident.to_string(), "bar"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.