Skip to content

Commit c4a6be5

Browse files
authored
Merge pull request #843 from DougGregor/subscript-expr
Parse subscript expression with no arguments (e.g., `array[]`).
2 parents 8f36550 + ed76af0 commit c4a6be5

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
@@ -596,7 +596,12 @@ extension Parser {
596596
// Check for a [expr] suffix.
597597
// Note that this cannot be the start of a new line.
598598
if let lsquare = self.consume(if: .leftSquareBracket, where: { !$0.isAtStartOfLine }) {
599-
let args = self.parseArgumentListElements(inLetOrVar: inLetOrVar)
599+
let args: [RawTupleExprElementSyntax]
600+
if self.at(.rightSquareBracket) {
601+
args = []
602+
} else {
603+
args = self.parseArgumentListElements(inLetOrVar: inLetOrVar)
604+
}
600605
let (unexpectedBeforeRSquare, rsquare) = self.expect(.rightSquareBracket)
601606

602607
// 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
@@ -437,7 +437,13 @@ final class ExpressionTests: XCTestCase {
437437
)
438438
}
439439

440-
func testRangeSubscript() {
440+
func testSubscript() {
441+
AssertParse(
442+
"""
443+
array[]
444+
"""
445+
)
446+
441447
AssertParse(
442448
"""
443449
text[...]

0 commit comments

Comments
 (0)