@@ -865,7 +865,6 @@ static bool typeCheckHasSymbolStmtConditionElement(StmtConditionElement &elt,
865865static bool typeCheckBooleanStmtConditionElement (StmtConditionElement &elt,
866866 DeclContext *dc) {
867867 Expr *E = elt.getBoolean ();
868- assert (!E->getType () && " the bool condition is already type checked" );
869868 bool hadError = TypeChecker::typeCheckCondition (E, dc);
870869 elt.setBoolean (E);
871870 return hadError;
@@ -1042,9 +1041,9 @@ class StmtChecker : public StmtVisitor<StmtChecker, Stmt*> {
10421041 // / DC - This is the current DeclContext.
10431042 DeclContext *DC;
10441043
1045- // / Skip type checking any elements inside 'BraceStmt', also this is
1046- // / propagated to ConstraintSystem .
1047- bool LeaveBraceStmtBodyUnchecked = false ;
1044+ // / The BraceStmts that should be type-checked. This should always be `All`,
1045+ // / unless we're lazy type-checking for e.g completion .
1046+ BraceStmtChecking BraceChecking = BraceStmtChecking::All ;
10481047
10491048 ASTContext &getASTContext () const { return Ctx; };
10501049
@@ -1503,7 +1502,7 @@ class StmtChecker : public StmtVisitor<StmtChecker, Stmt*> {
15031502 // FIXME: This is a hack to avoid cycles through NamingPatternRequest when
15041503 // doing lazy type-checking, we ought to fix the request to be granular in
15051504 // the type-checking work it kicks.
1506- bool skipWhere = LeaveBraceStmtBodyUnchecked &&
1505+ bool skipWhere = (BraceChecking != BraceStmtChecking::All) &&
15071506 Ctx.SourceMgr .hasIDEInspectionTargetBuffer ();
15081507
15091508 TypeChecker::typeCheckForEachPreamble (DC, S, skipWhere);
@@ -1738,11 +1737,19 @@ class StmtChecker : public StmtVisitor<StmtChecker, Stmt*> {
17381737 auto sourceFile = DC->getParentSourceFile ();
17391738 checkLabeledStmtShadowing (getASTContext (), sourceFile, S);
17401739
1741- // Type-check the 'do' body. Type failures in here will generally
1742- // not cause type failures in the 'catch' clauses.
1743- Stmt *newBody = S->getBody ();
1744- typeCheckStmt (newBody);
1745- S->setBody (newBody);
1740+ {
1741+ // If we have do-catch body checking enabled, make sure we visit the
1742+ // BraceStmt.
1743+ std::optional<llvm::SaveAndRestore<BraceStmtChecking>> braceChecking;
1744+ if (BraceChecking == BraceStmtChecking::OnlyDoCatchBody)
1745+ braceChecking.emplace (BraceChecking, BraceStmtChecking::All);
1746+
1747+ // Type-check the 'do' body. Type failures in here will generally
1748+ // not cause type failures in the 'catch' clauses.
1749+ Stmt *newBody = S->getBody ();
1750+ typeCheckStmt (newBody);
1751+ S->setBody (newBody);
1752+ }
17461753
17471754 // Do-catch statements always limit exhaustivity checks.
17481755 bool limitExhaustivityChecks = true ;
@@ -2192,7 +2199,7 @@ void StmtChecker::typeCheckASTNode(ASTNode &node) {
21922199}
21932200
21942201Stmt *StmtChecker::visitBraceStmt (BraceStmt *BS) {
2195- if (LeaveBraceStmtBodyUnchecked )
2202+ if (BraceChecking != BraceStmtChecking::All )
21962203 return BS;
21972204
21982205 // Diagnose defer statement being last one in block (only if
@@ -2218,12 +2225,12 @@ Stmt *StmtChecker::visitBraceStmt(BraceStmt *BS) {
22182225}
22192226
22202227void TypeChecker::typeCheckASTNode (ASTNode &node, DeclContext *DC,
2221- bool LeaveBodyUnchecked ) {
2228+ BraceStmtChecking braceChecking ) {
22222229 StmtChecker stmtChecker (DC);
22232230 // FIXME: 'ActiveLabeledStmts', etc. in StmtChecker are not
22242231 // populated. Since they don't affect "type checking", it's doesn't cause
22252232 // any issue for now. But it should be populated nonetheless.
2226- stmtChecker.LeaveBraceStmtBodyUnchecked = LeaveBodyUnchecked ;
2233+ stmtChecker.BraceChecking = braceChecking ;
22272234 stmtChecker.typeCheckASTNode (node);
22282235}
22292236
@@ -2769,7 +2776,7 @@ bool TypeCheckASTNodeAtLocRequest::evaluate(
27692776 }
27702777 }
27712778
2772- TypeChecker::typeCheckASTNode (finder.getRef (), DC, /* LeaveBodyUnchecked= */ false );
2779+ TypeChecker::typeCheckASTNode (finder.getRef (), DC);
27732780 return false ;
27742781}
27752782
0 commit comments