Skip to content

Commit ed76af0

Browse files
committed
Parse subscript expression with no arguments (e.g., array[]).
1 parent 79e979f commit ed76af0

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

Sources/SwiftParser/Expressions.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,12 @@ extension Parser {
594594
// Check for a [expr] suffix.
595595
// Note that this cannot be the start of a new line.
596596
if let lsquare = self.consume(if: .leftSquareBracket, where: { !$0.isAtStartOfLine }) {
597-
let args = self.parseArgumentListElements(inLetOrVar: inLetOrVar)
597+
let args: [RawTupleExprElementSyntax]
598+
if self.at(.rightSquareBracket) {
599+
args = []
600+
} else {
601+
args = self.parseArgumentListElements(inLetOrVar: inLetOrVar)
602+
}
598603
let (unexpectedBeforeRSquare, rsquare) = self.expect(.rightSquareBracket)
599604

600605
// If we can parse trailing closures, do so.

Tests/SwiftParserTest/Expressions.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,13 @@ final class ExpressionTests: XCTestCase {
431431
)
432432
}
433433

434-
func testRangeSubscript() {
434+
func testSubscript() {
435+
AssertParse(
436+
"""
437+
array[]
438+
"""
439+
)
440+
435441
AssertParse(
436442
"""
437443
text[...]

0 commit comments

Comments
 (0)