New test case to show the problem fixed by commit 61ce47014b

Fix new test case from commit fcaba99c81edcb8320856cb55367e1d8a9176675

Adding the review changes to #3193
This commit is contained in:
Gary Liu
2016-06-22 22:38:12 -04:00
parent 61ce47014b
commit ac53a1ef45
2 changed files with 51 additions and 13 deletions

View File

@@ -1031,26 +1031,22 @@ void PatternMatchEmission::emitWildcardDispatch(ClauseMatrix &clauses,
bool hasGuard = guardExpr != nullptr;
assert(!hasGuard || !clauses[row].isIrrefutable());
auto stmt = clauses[row].getClientData<CaseStmt>();
auto stmt = clauses[row].getClientData<Stmt>();
assert(isa<CaseStmt>(stmt) || isa<CatchStmt>(stmt));
bool hasMultipleItems = false;
if (stmt->getKind() == StmtKind::Case) {
ArrayRef<CaseLabelItem> labelItems = stmt->getCaseLabelItems();
hasMultipleItems = labelItems.size() > 1;
if (auto *caseStmt = dyn_cast<CaseStmt>(stmt)) {
hasMultipleItems = caseStmt->getCaseLabelItems().size() > 1;
}
// Bind the rest of the patterns.
bindIrrefutablePatterns(clauses[row], args, !hasGuard, hasMultipleItems);
// Emit the guard branch, if it exists.
if (guardExpr) {
if (stmt->getKind() == StmtKind::Case) {
SGF.usingImplicitVariablesForPattern(clauses[row].getCasePattern(), stmt, [&]{
this->emitGuardBranch(guardExpr, guardExpr, failure);
});
} else {
assert(stmt->getKind() == StmtKind::Catch);
emitGuardBranch(guardExpr, guardExpr, failure);
}
SGF.usingImplicitVariablesForPattern(clauses[row].getCasePattern(), dyn_cast<CaseStmt>(stmt), [&]{
this->emitGuardBranch(guardExpr, guardExpr, failure);
});
}
// Enter the row.
@@ -2190,6 +2186,12 @@ public:
void SILGenFunction::usingImplicitVariablesForPattern(Pattern *pattern, CaseStmt *stmt,
const llvm::function_ref<void(void)> &f) {
// Early exit for CatchStmt
if (!stmt) {
f();
return;
}
ArrayRef<CaseLabelItem> labelItems = stmt->getCaseLabelItems();
auto expectedPattern = labelItems[0].getPattern();