Skip to content

Commit

Permalink
fix: pub is required on return for entry points (#3616)
Browse files Browse the repository at this point in the history
# Description

## Problem\*

Resolves #3344 and #3632

## Summary\*



## Additional Context



## Documentation\*

Check one:
- [X] No documentation needed.
- [ ] Documentation included in this PR.
- [ ] **[Exceptional Case]** 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.
  • Loading branch information
guipublic committed Dec 5, 2023
1 parent 9827dfe commit 7f1d796
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
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
}
}

0 comments on commit 7f1d796

Please sign in to comment.