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

Improve misleading error messages for struct typos #6215

Closed
iAmMichaelConnor opened this issue Oct 3, 2024 · 2 comments · Fixed by #6236
Closed

Improve misleading error messages for struct typos #6215

iAmMichaelConnor opened this issue Oct 3, 2024 · 2 comments · Fixed by #6236
Assignees
Labels
enhancement New feature or request

Comments

@iAmMichaelConnor
Copy link
Collaborator

iAmMichaelConnor commented Oct 3, 2024

Problem

Not sure if it's possible to easily identify this, but occasionally I've mistyped instantiations of structs. Maybe a = instead of a :, or a missing ,. The errors I get are misleading and don't help me find the typo.

Take this code:

struct Foo {
    a: Field,
    b: Field,
}

fn main() -> pub Field {
    let foo = Foo { a: 12, b: 32 }; // Here's the instantiation we care about.
    foo.a * foo.b
}

#[test]
fn test_main() {
    let x = main();
}

Suppose I put = instead of ::

struct Foo {
    a: Field,
    b: Field,
}

fn main() -> pub Field {
    let foo = Foo { a = 12, b: 32 }; // typo here
    foo.a * foo.b
}

#[test]
fn test_main() {
    let x = main();
}

I get errors: Cannot find Foo in this scope and Expected a ; separating these two statements.

Suppose I forget a ,:

struct Foo {
    a: Field,
    b: Field,
}

fn main() -> pub Field {
    let foo = Foo { a: 12 b: 32 }; // Missing comma. It's harder to spot with big structs that span lines.
    foo.a * foo.b
}

#[test]
fn test_main() {
    let x = main();
}

I get errors: Cannot find Foo in this scope and Expected a ; separating these two statements, Expected a binary operator but found :.

Happy Case

I have no idea how complicated it is to identify, so you might decide to simply close this issue. But it would be cool if it could infer: "Hey, you might be missing a comma, you plonker" or "Hey, use a colon instead of a = inside a struct, you plonker".

Workaround

None

Workaround Description

No response

Additional Context

No response

Project Impact

None

Blocker Context

No response

Would you like to submit a PR for this Issue?

None

Support Needs

No response

@iAmMichaelConnor iAmMichaelConnor added the enhancement New feature or request label Oct 3, 2024
@github-project-automation github-project-automation bot moved this to 📋 Backlog in Noir Oct 3, 2024
@asterite asterite self-assigned this Oct 7, 2024
github-merge-queue bot pushed a commit that referenced this issue Oct 8, 2024
…6236)

# Description

## Problem

Resolves #6215

## Summary

If we get '=' instead of ':' we error but continue parsing the field
value.

## Additional Context

None.

## Documentation

Check one:
- [x] No documentation needed.
- [ ] Documentation included in this PR.
- [ ] **[For Experimental Features]** 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 Oct 8, 2024
@iAmMichaelConnor
Copy link
Collaborator Author

@asterite @jfecher thanks for resolving the first part of this issue.
It looks like this issue got auto-closed, but I suspect 2nd part of this issue (an accidentally-missing comma) is still unresolved. :)

@asterite
Copy link
Collaborator

asterite commented Nov 8, 2024

It seems it's solved too, but let me know otherwise:

Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: ✅ Done
Development

Successfully merging a pull request may close this issue.

2 participants