[SILGen] Fix case emission when there are no case body vars

We want to call the `bodyEmitter`, since that has the extra logic
necessary to handle `do-catch` statements. Previously this didn't
cause any issues since `hasCaseBodyVariables` would have always been
true for parsed `do-catch`s, but I'm planning on changing that.
This commit is contained in:
Hamish Knight
2025-09-09 13:48:40 +01:00
parent 805b6d9c39
commit 63286ae3f0
2 changed files with 16 additions and 1 deletions

View File

@@ -2958,7 +2958,7 @@ void PatternMatchEmission::emitSharedCaseBlocks(
SWIFT_DEFER { assert(SGF.getCleanupsDepth() == PatternMatchStmtDepth); };
if (!caseBlock->hasCaseBodyVariables()) {
emitCaseBody(caseBlock);
bodyEmitter(caseBlock);
continue;
}

View File

@@ -0,0 +1,15 @@
// RUN: %target-swift-emit-silgen %s -verify
enum E : Error {
case a(Int), b(Int)
}
func bar() throws {}
// Make sure we can correctly emit this without crashing.
func foo() throws {
do {
try bar()
} catch E.a, E.b {
}
}