-
Notifications
You must be signed in to change notification settings - Fork 439
Add diagnostics for missing modifier in operator declaration #1448
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
Conversation
7da6fdf
to
7d5684e
Compare
7d5684e
to
0a98797
Compare
@@ -1964,9 +1964,16 @@ extension Parser { | |||
} else { | |||
unexpectedAtEnd = nil | |||
} | |||
|
|||
var modifiers: RawModifierListSyntax? = attrs.modifiers | |||
if modifiers == nil, unexpectedBeforeOperatorKeyword == nil { |
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 check the unexpectedBeforeOperatorKeyword
here to keep testOperatorDecl10
produce the same diagnostics as the old parser. Not sure whether this makes sense🤔
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 haven’t looked at your changes in detail yet but I think the way to fix this is to change how OperatorDecl
is represented. It shouldn’t have an arbitrary ModifierList
but instead require a single child that can be either of the following tokens: prefix
, infix
, postfix
. And then parseOperatorDeclaration
wouldn’t actually be passed a DeclAttributes
(which is essentially attributes + modifiers). Instead, it would require some handling in parseDecl
earlier on.
Does this make sense to you?
My changes just handled the case that missing modifier for operator declaration. Your comments reminded me that the wrong modifier here is also not handled yet and I have updated the codes. 😀 As for the implementation, I prefer to parse the modifier list in |
prefix 1️⃣postfix operator ** : PrecedenceGroup | ||
""", | ||
diagnostics: [ | ||
DiagnosticSpec(message: "unexpected code 'postfix' 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.
The old parser generates 'postfix' contradicts previous modifier 'prefix' here. If my changes work, I could optimize the diagnostics message here later.
91c5978
to
c0c5647
Compare
I disagree. With the current design, if you are given an arbitrary SwiftSyntax tree, nothing guarantees you that an operator declaration has a |
c0c5647
to
d7c4d4b
Compare
I have refactored how According to the doc, we can not have attributes in operator declarations, so I have also removed the attributes in As for SwiftParser,
I think handling in the early stage of So I make the attributes and modifiers list parsed as before, and get them handled in If there is anything I missed, please feel free to let me know. Thanks in advance! |
dfaa2bd
to
5cb2987
Compare
To achieve this, I made a most straightforward way: make an extra call of Considering I call the extra Also, since I call the extra |
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.
Yes, this looks much simpler now. I’ve got a few local comments inline, after that it’s ready to be merged.
5cb2987
to
8aa865d
Compare
Sorry for committing some test codes before. I have already removed them.😁 |
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. Let’s get this merged.
@swift-ci Please test |
https://github.com/apple/swift/blob/main/test/attr/accessibility.swift failed to round-trip in the parser. Could you investigate what’s going wrong here? A good place to start is
|
I think the problem lies in that My solution is to add a new Actually, this problem is supposed to be detected by |
@swift-ci please test |
3c8d46e
to
5300fa7
Compare
869eafb
to
7a7c56a
Compare
Oh, and two more things: Looks like there is a merge conflict and can you squash your commits and force push? It makes for a nicer commit history IMO. |
7a7c56a
to
cf641d8
Compare
Done! |
@swift-ci Please test |
@swift-ci Please test Windows |
1 similar comment
@swift-ci Please test Windows |
Sorry @StevenWong12, looks like introduced another conflict by merging #1668. Could you rebase one more time? |
Head branch was pushed to by a user without write access
cf641d8
to
1dc5a41
Compare
Done! I noticed that there is a regression test(SwiftFormatPrettyPrintTests.OperatorDeclTests) in |
@swift-ci please test |
Could you please trigger the test on Windows? @kimdv |
@swift-ci please test Windows |
And another merge conflict, this time from #1711. Sorry that you continue to need to rebase this PR. |
When rebased I'll merge tomorrow if it's not merged before or if it's not okay @ahoppen 😁 |
Assign precedence to most of declaration modifiers Add diagnostic for missing fixity in operator declaration Make `unowned` parsing accept `RecoveryConsumptionHandle`
1dc5a41
to
dbf2a8b
Compare
That's not a big deal. 😄 Already rebased. |
@swift-ci please test |
@swift-ci please test windows |
I think maybe we should include the pr(swiftlang/swift-format#536) in Could you please trigger that again? @kimdv |
@swift-ci please test |
Doh! Sorry about that. |
Thank you. 😁 |
Part of #1373