Skip to content

Commit bc36c5a

Browse files
committed
Fix a bug that cause the parser to not terminate if we recoverd to a case item
1 parent e001682 commit bc36c5a

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
@@ -2689,6 +2689,9 @@ extension Parser {
26892689
} else if allowStandaloneStmtRecovery && (self.atStartOfExpression() || self.atStartOfStatement() || self.atStartOfDeclaration()) {
26902690
// Synthesize a label for the stamenent or declaration that isn't coverd by a case right now.
26912691
let statements = parseSwitchCaseBody()
2692+
if statements.isEmpty {
2693+
break
2694+
}
26922695
elements.append(
26932696
.switchCase(
26942697
RawSwitchCaseSyntax(

Tests/SwiftParserTest/ExpressionTests.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,4 +1231,15 @@ final class StatementExpressionTests: XCTestCase {
12311231
]
12321232
)
12331233
}
1234+
1235+
func testStandaloneAtCaseInSwitch() {
1236+
AssertParse(
1237+
"""
1238+
switch x {
1239+
1️⃣@case
1240+
}
1241+
""",
1242+
diagnostics: [DiagnosticSpec(message: "unexpected code '@case' in 'switch' statement")]
1243+
)
1244+
}
12341245
}

0 commit comments

Comments
 (0)