@@ -1031,26 +1031,22 @@ void PatternMatchEmission::emitWildcardDispatch(ClauseMatrix &clauses,
1031
1031
bool hasGuard = guardExpr != nullptr ;
1032
1032
assert (!hasGuard || !clauses[row].isIrrefutable ());
1033
1033
1034
- auto stmt = clauses[row].getClientData <CaseStmt>();
1034
+ auto stmt = clauses[row].getClientData <Stmt>();
1035
+ assert (isa<CaseStmt>(stmt) || isa<CatchStmt>(stmt));
1036
+
1035
1037
bool hasMultipleItems = false ;
1036
- if (stmt->getKind () == StmtKind::Case) {
1037
- ArrayRef<CaseLabelItem> labelItems = stmt->getCaseLabelItems ();
1038
- hasMultipleItems = labelItems.size () > 1 ;
1038
+ if (auto *caseStmt = dyn_cast<CaseStmt>(stmt)) {
1039
+ hasMultipleItems = caseStmt->getCaseLabelItems ().size () > 1 ;
1039
1040
}
1040
-
1041
+
1041
1042
// Bind the rest of the patterns.
1042
1043
bindIrrefutablePatterns (clauses[row], args, !hasGuard, hasMultipleItems);
1043
1044
1044
1045
// Emit the guard branch, if it exists.
1045
1046
if (guardExpr) {
1046
- if (stmt->getKind () == StmtKind::Case) {
1047
- SGF.usingImplicitVariablesForPattern (clauses[row].getCasePattern (), stmt, [&]{
1048
- this ->emitGuardBranch (guardExpr, guardExpr, failure);
1049
- });
1050
- } else {
1051
- assert (stmt->getKind () == StmtKind::Catch);
1052
- emitGuardBranch (guardExpr, guardExpr, failure);
1053
- }
1047
+ SGF.usingImplicitVariablesForPattern (clauses[row].getCasePattern (), dyn_cast<CaseStmt>(stmt), [&]{
1048
+ this ->emitGuardBranch (guardExpr, guardExpr, failure);
1049
+ });
1054
1050
}
1055
1051
1056
1052
// Enter the row.
@@ -2190,6 +2186,12 @@ class Lowering::PatternMatchContext {
2190
2186
2191
2187
void SILGenFunction::usingImplicitVariablesForPattern (Pattern *pattern, CaseStmt *stmt,
2192
2188
const llvm::function_ref<void (void )> &f) {
2189
+ // Early exit for CatchStmt
2190
+ if (!stmt) {
2191
+ f ();
2192
+ return ;
2193
+ }
2194
+
2193
2195
ArrayRef<CaseLabelItem> labelItems = stmt->getCaseLabelItems ();
2194
2196
auto expectedPattern = labelItems[0 ].getPattern ();
2195
2197
0 commit comments