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

Introduce DuplicateAnnotationListing bug checker #1044

Open
4 tasks done
mohamedsamehsalah opened this issue Feb 18, 2024 · 2 comments · May be fixed by #1070
Open
4 tasks done

Introduce DuplicateAnnotationListing bug checker #1044

mohamedsamehsalah opened this issue Feb 18, 2024 · 2 comments · May be fixed by #1070
Assignees

Comments

@mohamedsamehsalah
Copy link
Contributor

mohamedsamehsalah commented Feb 18, 2024

Problem

Duplicate entries inside annotation listing are a common mistake that should be flagged.

Description of the proposed new feature

  • Support a stylistic preference.
  • Avoid a common gotcha, or potential problem.
  • Improve performance.

Introduce a new BugChecker to flag duplicate entries as this is a common mistake. Similar to LexicographicalAnnotationListing, the new BugChecker should identify and handle duplicate entries to improve code quality and reduce potential errors.

I would like to rewrite the following code:

            @A("foo", "bar", "foo")
            A duplicateAnnotations();

to:

            @A("foo", "bar")
            A duplicateAnnotations();

Considerations

👉 To consider: A duplicate entry is a duplicate pointer reference and not just the same name.
👉 Open question: Are there situations where we do not want to flag this ?

Participation

  • I am willing to submit a pull request to implement this improvement.

Additional context

See this comment.


Edit 1: Update requirements based on this.

@Stephan202
Copy link
Member

Stephan202 commented Feb 19, 2024

Thanks for filing this issue @mohamedsamehsalah! One key point of feedback: I think we're looking for an analog of LexicographicalAnnotationAttributeListing, i.e. a check that replaces @A("foo", "bar", "foo") with @A("foo", "bar").

(Repeated annotations such as @Baz() @Baz() are rejected by the compiler, unless they're declared @Repeatable, in which case the repetition likely is intended.)

Edit: I see that this comment is indeed located on the wrong class. That's my fault!

@Stephan202
Copy link
Member

W.r.t. your considerations:

  • I'm not sure how pointer references factor in, but since only primitives, enum values and strings can be annotation arguments, the invariant holds that a value is a duplicated if and only if it is equal to some other value inside the same annotation attribute.
  • There are likely cases we'll want to exclude, but none come to mind right now. We might want to run a first version against the Picnic code base to assess what is flagged.

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