Skip to content

Commit 7db61b4

Browse files
committed
Fix a bug that cause the parser to not terminate if we recoverd to a case item
1 parent 243a1d3 commit 7db61b4

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

Sources/SwiftParser/Expressions.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2253,6 +2253,9 @@ extension Parser {
22532253
} else if allowStandaloneStmtRecovery && (self.atStartOfExpression() || self.atStartOfStatement() || self.atStartOfDeclaration()) {
22542254
// Synthesize a label for the stamenent or declaration that isn't coverd by a case right now.
22552255
let statements = parseSwitchCaseBody()
2256+
if statements.isEmpty {
2257+
break
2258+
}
22562259
elements.append(
22572260
.switchCase(
22582261
RawSwitchCaseSyntax(

Tests/SwiftParserTest/ExpressionTests.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1641,4 +1641,15 @@ final class StatementExpressionTests: XCTestCase {
16411641
]
16421642
)
16431643
}
1644+
1645+
func testStandaloneAtCaseInSwitch() {
1646+
AssertParse(
1647+
"""
1648+
switch x {
1649+
1️⃣@case
1650+
}
1651+
""",
1652+
diagnostics: [DiagnosticSpec(message: "unexpected code '@case' in 'switch' statement")]
1653+
)
1654+
}
16441655
}

0 commit comments

Comments
 (0)