Skip to content

Commit

Permalink
Check function arg visibility
Browse files Browse the repository at this point in the history
  • Loading branch information
aakoshh committed Oct 17, 2024
1 parent 99d88e5 commit 52dbd26
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
8 changes: 8 additions & 0 deletions compiler/noirc_frontend/src/elaborator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,14 @@ impl<'context> Elaborator<'context> {
func_meta.return_type(),
name.span(),
);
for (_, typ, _) in func_meta.parameters.iter() {
self.check_type_is_not_more_private_then_item(
&name,
modifiers.visibility,
typ,
name.span(),
);
}
}

self.introduce_generics_into_scope(func_meta.all_generics.clone());
Expand Down
14 changes: 7 additions & 7 deletions compiler/noirc_frontend/src/tests/visibility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ 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 {};
pub fn no_unused_warnings() {
let _: Bar = Foo {};
}
fn main() {}
"#;
Expand All @@ -68,9 +68,9 @@ fn errors_if_type_alias_aliases_more_private_type_in_generic() {
pub struct Generic<T> { value: T }
struct Foo {}
pub type Bar = Generic<Foo>;
pub fn no_unused_warnings(_b: Bar) {
pub fn no_unused_warnings() {
let _ = Foo {};
let _ = Generic { value: 1 };
let _: Bar = Generic { value: Foo {} };
}
fn main() {}
"#;
Expand Down Expand Up @@ -133,13 +133,13 @@ fn errors_if_pub_function_leaks_private_type_in_arg() {
struct Bar {}
pub fn bar(_bar: Bar) {}
pub fn foo() {
bar(Bar{});
pub fn no_unused_warnings() {
let _ = Bar {};
}
}
fn main() {}
"#;
assert_type_visibility_error(src, "Bar", "foo");
assert_type_visibility_error(src, "Bar", "bar");
}

#[test]
Expand Down

0 comments on commit 52dbd26

Please sign in to comment.