Skip to content

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

Merged
merged 1 commit into from
Oct 12, 2024

Conversation

ahoppen
Copy link
Member

@ahoppen ahoppen commented Oct 2, 2024

@ahoppen ahoppen requested a review from rintaro October 2, 2024 20:17
@ahoppen ahoppen requested a review from bnbarham as a code owner October 2, 2024 20:18
@ahoppen
Copy link
Member Author

ahoppen commented Oct 2, 2024

@swift-ci Please test

@ahoppen ahoppen enabled auto-merge October 2, 2024 21:37
@ahoppen ahoppen disabled auto-merge October 2, 2024 21:37
@@ -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))),
Copy link
Member

@rintaro rintaro Oct 3, 2024

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]?

@ahoppen
Copy link
Member Author

ahoppen commented Oct 3, 2024

@swift-ci Please test

@ahoppen
Copy link
Member Author

ahoppen commented Oct 3, 2024

@swift-ci Please test Windows

@ahoppen
Copy link
Member Author

ahoppen commented Oct 4, 2024

@swift-ci Please test Linux

1 similar comment
@ahoppen
Copy link
Member Author

ahoppen commented Oct 4, 2024

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

@rintaro rintaro Oct 4, 2024

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?

Copy link
Member Author

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

@ahoppen
Copy link
Member Author

ahoppen commented Oct 9, 2024

@swift-ci Please test

@ahoppen ahoppen enabled auto-merge October 9, 2024 23:45
@ahoppen
Copy link
Member Author

ahoppen commented Oct 10, 2024

@swift-ci Please test Windows

@ahoppen
Copy link
Member Author

ahoppen commented Oct 11, 2024

@swift-ci Please test macOS

@ahoppen ahoppen merged commit 3a7e378 into swiftlang:main Oct 12, 2024
3 checks passed
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