Skip to content

Commit 5cc4cdc

Browse files
authored
Merge pull request #840 from DougGregor/keypath-integer-literal-component
Fix parsing of key paths that involve `.<integer literal>`.
2 parents 79e979f + 675f7f9 commit 5cc4cdc

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

Sources/SwiftParser/Expressions.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -553,10 +553,12 @@ extension Parser {
553553

554554
// Check for a .foo suffix.
555555
if self.at(any: [.period, .prefixPeriod]) {
556-
// A key path is special, because it allows .[, unlike anywhere else. The
557-
// period itself should be left in the token stream. (.? and .! end up
558-
// being operators, and so aren't handled here.)
559-
if periodHasKeyPathBehavior && self.peek().tokenKind == .leftSquareBracket {
556+
// A key path is special, because it allows .[ and .<N>, unlike
557+
// anywhere else. The period itself should be left in the token stream.
558+
// (.? and .! end up being operators, and so aren't handled here.)
559+
if periodHasKeyPathBehavior &&
560+
(self.peek().tokenKind == .leftSquareBracket ||
561+
self.peek().tokenKind == .integerLiteral) {
560562
break
561563
}
562564

Tests/SwiftParserTest/Expressions.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,12 @@ final class ExpressionTests: XCTestCase {
111111
#"""
112112
_ = \Lens<[Int]>.[0]
113113
"""#)
114+
115+
AssertParse(
116+
#"""
117+
\(UnsafeRawPointer?, String).1
118+
"""#
119+
)
114120
}
115121

116122
func testBasicLiterals() {

0 commit comments

Comments
 (0)