-
Notifications
You must be signed in to change notification settings - Fork 440
Support parsing of key path subscripts on metatypes #2871
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
@swift-ci Please test |
Sources/SwiftParser/Types.swift
Outdated
@@ -260,7 +259,9 @@ extension Parser { | |||
|
|||
var loopProgress = LoopProgressCondition() | |||
while self.hasProgressed(&loopProgress) { | |||
if !stopAtFirstPeriod, self.at(.period) { | |||
if allowMemberTypes || (self.at(.period) && self.peek(isAt: .keyword(.Type), .keyword(.Protocol))), |
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.
What about nested types like: \Foo.Bar.[0]
?
1dc6bad
to
0a74d2f
Compare
@swift-ci Please test |
@swift-ci Please test Windows |
@swift-ci Please test Linux |
1 similar comment
@swift-ci Please test Linux |
if self.at(TokenSpec(.leftSquare, allowAtStartOfLine: false)) | ||
|| (components.isEmpty && self.at(.period) && self.peek(isAt: .leftSquare)) | ||
|| (components.allSatisfy({ $0.component.is(RawKeyPathPropertyComponentSyntax.self) }) && self.at(.period) |
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 found \T.?.?
is currently accepted, it also need this check.
Also, could this components.allSatisfy()
check be a flag outside the loop?
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.
Updated to disallow these key paths. I found a fun example along the way that’s valid 😭. This prevents us from diagnosing the .
as an unexpected token, which would generally be nicer diagnostics.
struct Foo {
var bar: Int?
}
infix operator .?.
func .?.(_ x: AnyKeyPath, _ a: Int) {}
var blah = 2
\Foo?.?.bar.?.blah
0a74d2f
to
7b52d07
Compare
@swift-ci Please test |
@swift-ci Please test Windows |
@swift-ci Please test macOS |
This is needed to support parsing eg.
https://github.com/swiftlang/swift/pull/73242/files#diff-a94f38549dc87ce27c438b255ae2f29c69cc1c2c5e5069f327c5c7fae7bc553dR667