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

Example code is missing pub keywords in returns #3452

Closed
microbecode opened this issue Nov 7, 2023 · 3 comments · Fixed by #3643
Closed

Example code is missing pub keywords in returns #3452

microbecode opened this issue Nov 7, 2023 · 3 comments · Fixed by #3643
Labels
bug Something isn't working

Comments

@microbecode
Copy link

Aim

Many of the examples in the documentation state something like this:

fn foo(x : Field, y : pub Field) -> Field {
    x + y
}

However, this syntax does not seem to be accepted (anymore). The return value should have the pub keyword.

Should this issue be listed as a 'bug' or an 'idea'? Dunno.

Expected Behavior

I expect the example codes to work.

Bug

Without the pub keyword I get error:
The pub keyword is mandatory for the entry-point function return type because the verifier cannot retrieve private witness and thus the function will not be able to return a 'priv' value

To Reproduce

Installation Method

Binary

Nargo Version

nargo 0.17 86704ba

Additional Context

No response

Would you like to submit a PR for this Issue?

Yes

Support Needs

No response

@microbecode microbecode added the bug Something isn't working label Nov 7, 2023
@github-project-automation github-project-automation bot moved this to 📋 Backlog in Noir Nov 7, 2023
@microbecode
Copy link
Author

Nothing? Nobody interested?

@TomAFrench
Copy link
Member

TomAFrench commented Nov 30, 2023

Hi @microbecode, thanks for opening this issue. The example you've posted is actually valid Noir, foo is a non-entrypoint function so its return value isn't required to be public. This is only the case for the function main so I expect what's happened is you've renamed the function to main which adds the extra restriction. It looks like we don't explicitly flag up this requirement for main in the docs however so we could add a section on that.

I've removed the public argument to foo in #3643 to help avoid any confusion in future.

@microbecode
Copy link
Author

Thanks! So problem solved.

github-merge-queue bot pushed a commit that referenced this issue Nov 30, 2023
# Description

## Problem\*

Resolves #3452

## Summary\*

This PR makes two changes in the docs:
1. I've removed the visibility modifier on an argument to the
non-entrypoint function `foo`. This code would compile but would also
raise a warning on `pub` being unnecessary and misleading so we should
just remove it.
2. `pub` was missing on a `main` function return value in
`7_mutability.md`.


## Additional Context



## Documentation\*

Check one:
- [ ] No documentation needed.
- [x] 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.
@github-project-automation github-project-automation bot moved this from 📋 Backlog to ✅ Done in Noir Nov 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants