Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: pub is required on return for entry points #3616

Merged
merged 7 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions compiler/noirc_frontend/src/hir/resolution/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -791,8 +791,8 @@ impl<'a> Resolver<'a> {
});
}

// 'pub_allowed' also implies 'pub' is required on return types
if self.pub_allowed(func)
// 'pub' is required on return types for entry point functions
if self.is_entry_point_function(func)
&& return_type.as_ref() != &Type::Unit
&& func.def.return_visibility == Visibility::Private
{
Expand Down Expand Up @@ -847,12 +847,9 @@ impl<'a> Resolver<'a> {
}

/// True if the 'pub' keyword is allowed on parameters in this function
/// 'pub' on function parameters is only allowed for entry point functions
fn pub_allowed(&self, func: &NoirFunction) -> bool {
if self.in_contract {
!func.def.is_unconstrained
} else {
func.name() == MAIN_FUNCTION
}
self.is_entry_point_function(func)
}

fn is_entry_point_function(&self, func: &NoirFunction) -> bool {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,9 @@ contract Foo {
open internal fn skibbidy(x: Field) -> pub Field {
x * 5
}
// Regression for issue #3344
#[contract_library_method]
fn foo(x : u8) -> u8 {
x
}
}
Loading