Skip to content

feat: check argument count and types on attribute function callback#5921

Merged
jfecher merged 9 commits intomasterfrom
ab/comptime-attribute-call-check-params
Sep 4, 2024
Merged

feat: check argument count and types on attribute function callback#5921
jfecher merged 9 commits intomasterfrom
ab/comptime-attribute-call-check-params

Conversation

@asterite
Copy link
Copy Markdown
Collaborator

@asterite asterite commented Sep 4, 2024

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:

#[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:

  • No documentation needed.
  • Documentation included in this PR.
  • [For Experimental Features] Documentation to be submitted in a separate PR.

PR Checklist

  • I have tested the changes locally.
  • I have formatted the changes with Prettier and/or cargo fmt on default settings.

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants