Skip to content

[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

Merged

Conversation

StevenWong12
Copy link
Contributor

To sync the changes in swiftlang/swift-syntax#1448 (review)

Copy link
Member

@ahoppen ahoppen left a 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 🤩

continue;
}
auto *attr = *it;
P.diagnose(attr->getLocation(), diag::operator_decl_should_not_contain_other_attributes, attr->getAttrName());
Copy link
Member

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.

@@ -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}}
Copy link
Member

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?

@StevenWong12 StevenWong12 force-pushed the diagnositic_on_modifiers_in_operatordecl branch from 916ae38 to 19dd7fd Compare April 20, 2023 02:09
@ahoppen
Copy link
Member

ahoppen commented Apr 20, 2023

@swift-ci Please smoke test

@StevenWong12
Copy link
Contributor Author

StevenWong12 commented Apr 20, 2023

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

<unknown>:0: error: unexpected attribute <<raw doc comment>> in operator declaration

It seems that some files used to build the stdlib use the <<raw doc comment>> as a DeclAttribute and the log indicates the latest building file is SIMDVector.swift, but I didn't see any inappropriate use of operator declaration there. Is there anything I missed? If not, maybe I should debug the building stage to locate the problem?

@StevenWong12 StevenWong12 marked this pull request as ready for review April 20, 2023 02:33
@ahoppen
Copy link
Member

ahoppen commented Apr 20, 2023

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 DAK_RawDocComment) for operator declarations.

@StevenWong12 StevenWong12 force-pushed the diagnositic_on_modifiers_in_operatordecl branch from 19dd7fd to 3cabe08 Compare April 21, 2023 15:40
@StevenWong12
Copy link
Contributor Author

StevenWong12 commented Apr 21, 2023

I've added doc comments as an allowable attribute in operator declaration and the stdlib can be successfully built now.

my bet right now is that you will be able to reproduce the issue with

But I still can not reproduce this problem locally. It's kind of weird.

@ahoppen
Copy link
Member

ahoppen commented Apr 21, 2023

Let’s see what CI has to say about it.

@swift-ci Please smoke test

@ahoppen ahoppen merged commit caeab58 into swiftlang:main Apr 28, 2023
@ahoppen
Copy link
Member

ahoppen commented Apr 28, 2023

Sorry, I forgot about this PR after I triggered CI. Merged now.

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.

2 participants