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

Spurious (bogus) error message when using 'mut' in a parameter type #7495

Closed
nickysn opened this issue Feb 24, 2025 · 0 comments · Fixed by #7501
Closed

Spurious (bogus) error message when using 'mut' in a parameter type #7495

nickysn opened this issue Feb 24, 2025 · 0 comments · Fixed by #7501
Assignees
Labels
bug Something isn't working

Comments

@nickysn
Copy link
Contributor

nickysn commented Feb 24, 2025

Aim

Compile a program with a locally mutable parameter, where the 'mut' keyword has been incorrectly placed inside the type: fn test_fn(q: mut u32) { } (instead of the correct fn test_fn(mut q: u32) { }) and get a reasonable (understandable by a human) compiler error.

Expected Behavior

The program should produce a readable compile error. For example, Rust produces this error:

error: expected type, found keyword `mut`
 --> src/main.rs:1:18
  |
1 | fn test_param(q: mut u32) {
  |                  ^^^ expected type

Bug

Noir produces a bogus warning about unnecessary pub keyword, followed by a long list of (mostly) spurious errors:

warning: unnecessary pub keyword on parameter for function test_fn
  ┌─ main.nr:1:4
  │
1 │ fn test_fn(q: mut u32) {
  │    ------- unnecessary pub parameter
  │
  = The `pub` keyword only has effects on arguments to the entry-point function of a program. Thus, adding it to other function parameters can be deceiving and should be removed

warning: unused variable q
  ┌─ main.nr:1:12
  │
1 │ fn test_fn(q: mut u32) {
  │            - unused variable 
  │

warning: unused variable main
  ┌─ main.nr:4:4
  │
4 │ fn main(x: Field, y: pub Field) {
  │    ---- unused variable 
  │

warning: unused function test_fn
  ┌─ main.nr:1:4
  │
1 │ fn test_fn(q: mut u32) {
  │    ------- unused function
  │

error: Cannot assign an expression of type (_) to a value of type Field
  ┌─ main.nr:4:8
  │
4 │ fn main(x: Field, y: pub Field) {
  │        --
  │

error: Expected a type but found 'mut'
  ┌─ main.nr:1:15
  │
1 │ fn test_fn(q: mut u32) {
  │               ---
  │

error: Expected a pattern but found a type - u32
  ┌─ main.nr:1:19
  │
1 │ fn test_fn(q: mut u32) {
  │                   --- u32 is a type and cannot be used as a variable name
  │

error: Expected a pattern but found 'u32'
  ┌─ main.nr:1:19
  │
1 │ fn test_fn(q: mut u32) {
  │                   ---
  │

error: Expected a pattern but found ')'
  ┌─ main.nr:1:22
  │
1 │ fn test_fn(q: mut u32) {
  │                      -
  │

error: Expected a pattern but found '{'
  ┌─ main.nr:1:24
  │
1 │ fn test_fn(q: mut u32) {
  │                        -
  │

error: Expected a pattern but found '}'
  ┌─ main.nr:2:1
  │
2 │ }
  │ -
  │

error: Expected a pattern but found 'fn'
  ┌─ main.nr:4:1
  │
4 │ fn main(x: Field, y: pub Field) {
  │ --
  │

error: Missing type for function parameter
  ┌─ main.nr:4:4
  │
4 │ fn main(x: Field, y: pub Field) {
  │    -----
  │

error: Expected a `,` separating these two parameters
  ┌─ main.nr:1:15
  │
1 │ fn test_fn(q: mut u32) {
  │               ---
  │

error: Expected a pattern but found ':'
  ┌─ main.nr:4:10
  │
4 │ fn main(x: Field, y: pub Field) {
  │          -
  │

error: Expected a `,` separating these two parameters
  ┌─ main.nr:4:8
  │
4 │ fn main(x: Field, y: pub Field) {
  │        -
  │

Aborting due to 12 previous errors

To Reproduce

  1. Create a new nargo package: nargo new mut_param
  2. Edit main.nr and replace it with the following code:
fn test_fn(q: mut u32) {
}

fn main(x: Field, y: pub Field) {
    assert(x != y);
}
  1. Run nargo compile and observe the list of errors.

Workaround

None

Workaround Description

No response

Additional Context

No response

Project Impact

Nice-to-have

Blocker Context

No response

Nargo Version

No response

NoirJS Version

No response

Proving Backend Tooling & Version

No response

Would you like to submit a PR for this Issue?

None

Support Needs

No response

@nickysn nickysn added the bug Something isn't working label Feb 24, 2025
@github-project-automation github-project-automation bot moved this to 📋 Backlog in Noir Feb 24, 2025
@asterite asterite self-assigned this Feb 24, 2025
@github-project-automation github-project-automation bot moved this from 📋 Backlog to ✅ Done in Noir Feb 24, 2025
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