Skip to content

Commit 9709af5

Browse files
committed
[ASTScope] Use labeled statements query to compute switch depth
For now, verify that this is equivalent to the switch depth tracked in the statement type checker's state.
1 parent 3612754 commit 9709af5

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

lib/Sema/TypeCheckStmt.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -877,7 +877,16 @@ class StmtChecker : public StmtVisitor<StmtChecker, Stmt*> {
877877
}
878878

879879
Stmt *visitFallthroughStmt(FallthroughStmt *S) {
880-
if (!SwitchLevel) {
880+
auto sourceFile = DC->getParentSourceFile();
881+
auto activeLabeledStmts = ASTScope::lookupLabeledStmts(
882+
sourceFile, S->getLoc());
883+
auto numSwitches = llvm::count_if(activeLabeledStmts,
884+
[](LabeledStmt *labeledStmt) {
885+
return isa<SwitchStmt>(labeledStmt);
886+
});
887+
assert(numSwitches == SwitchLevel);
888+
889+
if (!numSwitches) {
881890
getASTContext().Diags.diagnose(S->getLoc(),
882891
diag::fallthrough_outside_switch);
883892
return nullptr;

0 commit comments

Comments
 (0)