-
Notifications
You must be signed in to change notification settings - Fork 433
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
Handle missing comma i func params #3014
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 for picking up the PR, Kim!
I’m fixing the license header check failure here: swiftlang/github-workflows#105 |
b5af6bb
to
2449ca8
Compare
2449ca8
to
0fa02d8
Compare
Sources/SwiftParser/Parameters.swift
Outdated
trailingComma = self.consume(if: .comma) | ||
} else if !self.at(.rightParen) { | ||
let canParseIdentifier: Bool = withLookahead { | ||
$0.canParseTypeIdentifier(allowKeyword: false) || $0.canParseCustomAttribute() |
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.
assertParse(
"func f(_: any borrowing 1️⃣~Copyable) {}",
diagnostics: [
DiagnosticSpec(
message: "unexpected code '~Copyable' in parameter clause"
)
]
)
This test is failing @ahoppen.
failed - Expected 1 diagnostics but received 2:
1:24: expected ',' in parameter
1:25: expected identifier and ':' in parameter
Not sure how to handle this?
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.
$0.canParseCustomAttribute()
return true for ~Copyable
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.
Hmm, let’s just remove canParseCustomAttribute
then. Attributes on parameters aren’t very common anyway.
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 I added an self.at(.atSign)
that fixes the issue.
I self only know @
attributes for names. Is there others?
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, I just looked at canParesCustomAttribute
and it assumes that the @
has already been consumed. So, self.at(.atSign)
should be a consume(if:)
.
And we should probably check for the at sign first because canParseTypeIdentifier
can modify the Lookahead
’s state.
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.
Changed it to consuming it.
004b40b
to
eff3eb3
Compare
@swift-ci please test |
@swift-ci please test windows |
eff3eb3
to
8a70081
Compare
Sources/SwiftParser/Parameters.swift
Outdated
let canParseIdentifier: Bool = withLookahead { | ||
$0.canParseTypeIdentifier(allowKeyword: false) | ||
} | ||
|
||
let canParseAttribute: Bool = withLookahead { | ||
($0.consume(if: .atSign) != nil && $0.canParseCustomAttribute()) | ||
} | ||
|
||
if canParseIdentifier || canParseAttribute { | ||
trailingComma = Token(missing: .comma, arena: self.arena) | ||
} |
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.
Not sure if there is any noteworthy performance hit here?
We have two withLookahead
where we potentially only use canParseIdentifier
.
Was considering
let canParseIdentifier: Bool = withLookahead {
$0.canParseTypeIdentifier(allowKeyword: false)
}
if canParseIdentifier {
trailingComma = Token(missing: .comma, arena: self.arena)
}
let canParseAttribute: Bool = withLookahead {
$0.consume(if: .atSign) != nil && $0.canParseCustomAttribute()
}
if canParseAttribute {
trailingComma = Token(missing: .comma, arena: self.arena)
}
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 think your current implementation is good. This will only be hit for invalid code and we tend to not squeeze the last bit of performance for invalid code because it’s A LOT less common than valid code.
@swift-ci please test |
@swift-ci please test macOS |
@swift-ci please test Windows |
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.
Just one nitpick. Feel free to merge after you addressed it.
Sources/SwiftParser/Parameters.swift
Outdated
let canParseIdentifier: Bool = withLookahead { | ||
$0.canParseTypeIdentifier(allowKeyword: false) | ||
} | ||
|
||
let canParseAttribute: Bool = withLookahead { | ||
($0.consume(if: .atSign) != nil && $0.canParseCustomAttribute()) | ||
} | ||
|
||
if canParseIdentifier || canParseAttribute { | ||
trailingComma = Token(missing: .comma, arena: self.arena) | ||
} |
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 think your current implementation is good. This will only be hit for invalid code and we tend to not squeeze the last bit of performance for invalid code because it’s A LOT less common than valid code.
8a70081
to
ea8f816
Compare
@swift-ci please test |
@swift-ci please test windows |
@swift-ci please test macOS |
1 similar comment
@swift-ci please test macOS |
@ahoppen not sure I know why it failed. Tried to dig in the logs, and I don't seem to find anything 🤔 |
Looks like a non-deterministic failure. Let’s try again. @swift-ci Please test macOS |
@kimdv now it was something else that failed It still seem unrelated?
|
@swift-ci please test macOS |
I saw this PR: #886
Then I tought I would finish it 😄