-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Parser] Make parser aware of the unexpected attributes in operator declarations #65224
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] Make parser aware of the unexpected attributes in operator declarations #65224
Conversation
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.
Thanks, this is great work. Sorry for not providing you pointers earlier, I didn’t have a compiler build locally at the end of last week that I could have used to find the places to change but you figured this out really well on your own 🤩
lib/Parse/ParseDecl.cpp
Outdated
continue; | ||
} | ||
auto *attr = *it; | ||
P.diagnose(attr->getLocation(), diag::operator_decl_should_not_contain_other_attributes, attr->getAttrName()); |
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.
Could you add a Fix-It to this diagnostic to remove the attribute (similar to line 4599).
Could you format the line to only contain 80 columns? I usually run git-clang-format
, which (IIRC) you can install using Homebrew.
test/Parse/operator_decl.swift
Outdated
@@ -117,3 +117,5 @@ infix operator *<*< : F, Proto | |||
|
|||
// expected-error@+2 {{expected precedence group name after ':' in operator declaration}} | |||
postfix operator ++: // expected-error {{only infix operators may declare a precedence}} {{20-21=}} | |||
|
|||
dynamic prefix operator +!+ // expected-error{{unexpected attribute 'dynamic' in operator declaration}} |
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.
I see that you moved this test case. Could you keep the assertion that there should be a Fix-It to remove dynamic
, i.e. the `{{1-9=}} part?
Could you add a newline at the end of the file?
916ae38
to
19dd7fd
Compare
@swift-ci Please smoke test |
Hey @ahoppen, sorry for the late reply. I've modified my codes according to your suggestions. When I rebuild the stdlib locally, I got some errors as follows
It seems that some files used to build the stdlib use the |
I’m not 100% sure what’s going wrong here but my bet right now is that you will be able to reproduce the issue with /// some doc comment
prefix operator +!+ The compiler models doc comments as attributes and you are marking them as invalid. So, you should also be allowing doc comments (with attribute kind |
19dd7fd
to
3cabe08
Compare
I've added doc comments as an allowable attribute in operator declaration and the stdlib can be successfully built now.
But I still can not reproduce this problem locally. It's kind of weird. |
Let’s see what CI has to say about it. @swift-ci Please smoke test |
Sorry, I forgot about this PR after I triggered CI. Merged now. |
To sync the changes in swiftlang/swift-syntax#1448 (review)