@@ -1038,20 +1038,35 @@ void PatternMatchEmission::emitDispatch(ClauseMatrix &clauses, ArgArray args,
10381038 SGF.eraseBasicBlock (contBB);
10391039 return ;
10401040 }
1041-
1041+
10421042 // Otherwise, if there is no fallthrough, then the next row is
1043- // unreachable: emit a dead code diagnostic.
1043+ // unreachable: emit a dead code diagnostic if:
1044+ // 1) It's for a 'default' case (since Space Engine already handles
1045+ // unreachable enum case patterns) or it's for a enum case which
1046+ // has expression patterns since redundancy checking for such
1047+ // patterns isn't sufficiently done by the Space Engine.
1048+ // 2) It's for a case statement in a do-catch.
10441049 if (!clauses[firstRow].hasFallthroughTo ()) {
10451050 SourceLoc Loc;
10461051 bool isDefault = false ;
1052+ bool isParentDoCatch = false ;
1053+ bool caseHasExprPattern = false ;
10471054 if (auto *S = clauses[firstRow].getClientData <Stmt>()) {
10481055 Loc = S->getStartLoc ();
1049- if (auto *CS = dyn_cast<CaseStmt>(S))
1056+ if (auto *CS = dyn_cast<CaseStmt>(S)) {
1057+ caseHasExprPattern = llvm::any_of (
1058+ CS->getCaseLabelItems (), [&](const CaseLabelItem item) {
1059+ return item.getPattern ()->getKind () == PatternKind::Expr;
1060+ });
1061+ isParentDoCatch = CS->getParentKind () == CaseParentKind::DoCatch;
10501062 isDefault = CS->isDefault ();
1063+ }
10511064 } else {
10521065 Loc = clauses[firstRow].getCasePattern ()->getStartLoc ();
10531066 }
1054- SGF.SGM .diagnose (Loc, diag::unreachable_case, isDefault);
1067+ if (isParentDoCatch || isDefault || caseHasExprPattern) {
1068+ SGF.SGM .diagnose (Loc, diag::unreachable_case, isDefault);
1069+ }
10551070 }
10561071 }
10571072 }
0 commit comments