Skip to content

Commit 61ce470

Browse files
bryanpkcvivkong
authored andcommitted
Case statements are not the only kind that require wildcard dispatches and have guard branches.
1 parent add621a commit 61ce470

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

lib/SILGen/SILGenPattern.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,17 +1032,25 @@ void PatternMatchEmission::emitWildcardDispatch(ClauseMatrix &clauses,
10321032
assert(!hasGuard || !clauses[row].isIrrefutable());
10331033

10341034
auto stmt = clauses[row].getClientData<CaseStmt>();
1035-
ArrayRef<CaseLabelItem> labelItems = stmt->getCaseLabelItems();
1036-
bool hasMultipleItems = labelItems.size() > 1;
1035+
bool hasMultipleItems = false;
1036+
if (stmt->getKind() == StmtKind::Case) {
1037+
ArrayRef<CaseLabelItem> labelItems = stmt->getCaseLabelItems();
1038+
hasMultipleItems = labelItems.size() > 1;
1039+
}
10371040

10381041
// Bind the rest of the patterns.
10391042
bindIrrefutablePatterns(clauses[row], args, !hasGuard, hasMultipleItems);
10401043

10411044
// Emit the guard branch, if it exists.
10421045
if (guardExpr) {
1043-
SGF.usingImplicitVariablesForPattern(clauses[row].getCasePattern(), stmt, [&]{
1044-
this->emitGuardBranch(guardExpr, guardExpr, failure);
1045-
});
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+
}
10461054
}
10471055

10481056
// Enter the row.

0 commit comments

Comments
 (0)