-
Notifications
You must be signed in to change notification settings - Fork 439
Add correct diagnostic for missing parentheses #2012
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
Add correct diagnostic for missing parentheses #2012
Conversation
bd5f7d6
to
9de0862
Compare
0fe61be
to
8356e1c
Compare
8356e1c
to
c54b023
Compare
@swift-ci please test |
c54b023
to
b9a23a9
Compare
if self.at(.leftParen) { | ||
// If the next token is ':', then it looks like the code contained a non-shorthand closure parameter with a type annotation. | ||
// These need to be wrapped in parentheses. | ||
if self.at(.leftParen) || self.peek(isAt: .colon) { |
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 added this test and it fails because we are peeking here.
When at this place current token is comparisonPredicate
.
assertParse(
"""
withInvalidOrderings { (comparisonPredicate: @escaping (Int, Int) -> Bool) in
}
"""
)
So the peek seems not the correct solutions here.
Maybe we should do something like self.peek(isAt: .colon) && previousToken != .leftParen
What do you think @ahoppen
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.
@ahoppen 😬
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.
Sorry, it’s been a busy week and I missed the comment. Thanks for the ping.
The issue happens because in canPareClosureSignature
, we now stop at the arrow. Since we start doing skipSingle
at comparisonPredicate
. If you make the following change, then we’re calling skipSingle
on the opening (
, which consumes all the contents until the matching )
before the in
, including the ->
, which fixes the issue.
- if lookahead.consume(if: .leftParen) != nil { // Consume the ')'.
+ if lookahead.at(.leftParen) { // Consume the '('.
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.
Oh okay nice!
Thanks a lot.
And no worries! Take the time to reply when you can 😁
b9a23a9
to
a911e90
Compare
@swift-ci please test |
@swift-ci please test macOS |
@ahoppen the job fails here: https://ci.swift.org/job/swift-syntax-PR-macOS/3177/console Not sure why. Edit: |
a911e90
to
56548c7
Compare
@swift-ci please test |
It’s failing at the following test case. The state.withCriticalRegion { (1 + 2) }
for action in tracking {
action()
} And just to explain how I got to this: I clones the compiler repo and ran swift-parser-cli print-diags stdlib/public/Observation/Sources/Observation/ObservationRegistrar.swift Then I kept removing code from that file while still reproducing the failure until I ended up with the reduced example. |
56548c7
to
7fb3e7f
Compare
@ahoppen found it. Changed |
@swift-ci please test |
@swift-ci Please test Windows |
while !lookahead.at(.endOfFile, .rightParen) && lookahead.hasProgressed(&skipProgress) { | ||
while !lookahead.at(.endOfFile, .rightBrace, .keyword(.in)) && !lookahead.at(.arrow) && lookahead.hasProgressed(&skipProgress) { |
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.
Oh, yes, that does make sense. skipSingle
is looking for the rightParen
now that we previously consumed manually in lookahead.consume(if: .leftParen)
.
Resolves #1925