Skip to content

Commit 42c113d

Browse files
committed
Fix a bug that cause the parser to not terminate if we recoverd to a case item
1 parent 75c8bd6 commit 42c113d

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

Sources/SwiftParser/Statements.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -766,6 +766,9 @@ extension Parser {
766766
} else if allowStandaloneStmtRecovery && (self.atStartOfExpression() || self.atStartOfStatement() || self.atStartOfDeclaration()) {
767767
// Synthesize a label for the stamenent or declaration that isn't coverd by a case right now.
768768
let statements = parseSwitchCaseBody()
769+
if statements.isEmpty {
770+
break
771+
}
769772
elements.append(
770773
.switchCase(
771774
RawSwitchCaseSyntax(

Tests/SwiftParserTest/StatementTests.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,4 +618,14 @@ final class StatementTests: XCTestCase {
618618
)
619619
}
620620

621+
func testStandaloneAtCaseInSwitch() {
622+
AssertParse(
623+
"""
624+
switch x {
625+
1️⃣@case
626+
}
627+
""",
628+
diagnostics: [DiagnosticSpec(message: "unexpected code '@case' in 'switch' statement")]
629+
)
630+
}
621631
}

0 commit comments

Comments
 (0)