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

Error instead of panic when attribute function doesn't have the right arguments #5903

Closed
asterite opened this issue Sep 3, 2024 · 0 comments · Fixed by #5921
Closed

Error instead of panic when attribute function doesn't have the right arguments #5903

asterite opened this issue Sep 3, 2024 · 0 comments · Fixed by #5921
Labels
bug Something isn't working

Comments

@asterite
Copy link
Collaborator

asterite commented Sep 3, 2024

Aim

The compiler shouldn't panic if an attribute function doesn't have the expected arguments.

Expected Behavior

This code:

#[attr]
fn foo() {}

fn attr() -> Quoted {
}

fn main() {
    bar();
}

should give an error saying that attr should have a FunctionDefinition argument.

Similarly, if there's a first argument but it's not a FunctionDefinition, it should also error.

Bug

No error for the above case.

To Reproduce

Workaround

None

Workaround Description

No response

Additional Context

No response

Project Impact

None

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

@asterite asterite added the bug Something isn't working label Sep 3, 2024
@github-project-automation github-project-automation bot moved this to 📋 Backlog in Noir Sep 3, 2024
github-merge-queue bot pushed a commit that referenced this issue Sep 4, 2024
…5921)

# Description

## Problem

Resolves #5903

## Summary

Now the compiler will check that attribute function callbacks have at
least one argument, that that argument's type matches the corresponding
type, and that remaining arguments also match the types given.

Also previously errors on these callbacks were shown on the function
that had the attribute, instead of on the attribute, likely because
attributes didn't have a Span attached to them: this PR adds that too.

## Additional Context

The error message is still a bit strange because if you have code like
this:

```rust
#[attr]
fn foo() {}

fn attr() {}

fn main() {}
```

You get this:

```
error: Expected 0 arguments, but 1 was provided
  ┌─ src/main.nr:1:3
  │
1 │ #[attr]
  │   ---- Too many arguments
```

which kind of makes sense, because 1 implicit argument was provided but
0 are expected in the callback, but maybe the error should point out
that the callback actually needs one argument. Let me know if you think
we should improve the error message here... but at least it doesn't
error anymore.

Oh, I remember why I didn't improve that error message: the error should
likely be on the callback function, but it should point out that the
error happens because of a given attribute, so we need two different
locations for the error, which I think we currently doesn't support.

## 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 Sep 4, 2024
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.

1 participant