@@ -1409,7 +1409,15 @@ class SyntacticElementSolutionApplication
14091409 }
14101410
14111411 auto caseStmt = cast<CaseStmt>(rawCase.get <Stmt *>());
1412- visitCaseStmt (caseStmt);
1412+ // Body of the `case` statement can contain a `fallthrough`
1413+ // statement that requires both source and destination
1414+ // `case` preambles to be type-checked, so bodies of `case`
1415+ // statements should be visited after preambles.
1416+ visitCaseStmtPreamble (caseStmt);
1417+ }
1418+
1419+ for (auto *caseStmt : switchStmt->getCases ()) {
1420+ visitCaseStmtBody (caseStmt);
14131421
14141422 // Check restrictions on '@unknown'.
14151423 if (caseStmt->hasUnknownAttr ()) {
@@ -1436,7 +1444,7 @@ class SyntacticElementSolutionApplication
14361444 return doStmt;
14371445 }
14381446
1439- ASTNode visitCaseStmt (CaseStmt *caseStmt) {
1447+ void visitCaseStmtPreamble (CaseStmt *caseStmt) {
14401448 // Translate the patterns and guard expressions for each case label item.
14411449 for (auto &caseItem : caseStmt->getMutableCaseLabelItems ()) {
14421450 SolutionApplicationTarget caseTarget (&caseItem,
@@ -1453,11 +1461,16 @@ class SyntacticElementSolutionApplication
14531461 solution.getType (prev)->mapTypeOutOfContext ());
14541462 expected->setInterfaceType (type);
14551463 }
1464+ }
14561465
1457- // Translate the body.
1466+ void visitCaseStmtBody (CaseStmt *caseStmt) {
14581467 auto *newBody = visit (caseStmt->getBody ()).get <Stmt *>();
14591468 caseStmt->setBody (cast<BraceStmt>(newBody));
1469+ }
14601470
1471+ ASTNode visitCaseStmt (CaseStmt *caseStmt) {
1472+ visitCaseStmtPreamble (caseStmt);
1473+ visitCaseStmtBody (caseStmt);
14611474 return caseStmt;
14621475 }
14631476
0 commit comments