-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Parser] Improving diagnostics for access-level modifiers #68894
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
[Parser] Improving diagnostics for access-level modifiers #68894
Conversation
@ahoppen Are you OK with accepting this sort of improvement into the legacy parser? I would guess |
Yes, swift-syntax allows duplicate access level modifiers because it just models them as a list. ASTGen will need to diagnose these sorts of problems. And I think this change is a good improvement. It would be nice to add a test case for it, though. |
1511afc
to
f1e3c82
Compare
Cool! I updated the diagnostics' messages to reflect the latest from the discussion with @AnthonyLatsis and updated the existing tests to reflect the new diagnostics as @ahoppen requested. |
af6c0e2
to
3c9d6ca
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome! Just one optional stylistic suggestion.
@swift-ci please smoke test macOS |
3c9d6ca
to
481504d
Compare
@rintaro ping |
@swift-ci Please smoke test |
The change looks good to me. But I feel these all attribute diagnostics including others (e.g. "concurrency only") should be in Sema (TypeCheckAttr.cpp) not in Parse or ASTGen. For example, It's not a blocker for merging this PR though. |
I agree with @rintaro. Implementing these checks in the type checker will make them applicable to both the old parser and the new parser. |
@swift-ci Please test Windows |
481504d
to
86e1a1e
Compare
I just noticed I had mistakenly kept an extra argument on the note diagnostic. It's fixed now. I also ran the code formatter and cleaned up the commit message to make it more succinct. Sorry for making these changes after the review comments and the tests have been run. @AnthonyLatsis would you mind triggering the tests once more? |
Improve the diagnostics for situations where multiple access-level modifiers are used on the same declaration. Keep the original duplicate error message if the access levels are the same.
86e1a1e
to
e18bfab
Compare
@rintaro Do we want anyone else to take a look at this? |
@swift-ci please smoke test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your contribution! Exploring moving some of these attribute diagnostics out of the parser and into TypeCheckAttr.cpp would be a good next task if you're interested in continuing contributions in this area 🙂
I’m definitely interested! I’ll take a look at that once I have some time. I’d like to quickly thank @AnthonyLatsis for helping me a lot with this the process of making a contribution and @rintaro, @ahoppen and @hborla for the review and approval of my first pull request. |
Problem
When declaring a method with multiple access-level modifiers (a programming mistake), the current diagnostic is not clear nor accurate.
As an example, when we compile the following block of code:
We get the following diagnostics:
It can be argued that both modifiers are from the same "type" (access-level modifiers), but the example shows a situation where they aren't a duplicate of each other as the error message says.
Solution
The solution implemented on this pull request is a new diagnostic: an error message that describes the problem more clearly and a note that refers to the previous modifier by name.
Resolves #60914.