Skip to content

Commit faae25a

Browse files
committed
AST: The body of a CaseStmt is always a BraceStmt
1 parent 0e27645 commit faae25a

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

include/swift/AST/Stmt.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -945,13 +945,13 @@ class CaseStmt final
945945
SourceLoc ItemTerminatorLoc;
946946
CaseParentKind ParentKind;
947947

948-
llvm::PointerIntPair<Stmt *, 1, bool> BodyAndHasFallthrough;
948+
llvm::PointerIntPair<BraceStmt *, 1, bool> BodyAndHasFallthrough;
949949

950950
Optional<MutableArrayRef<VarDecl *>> CaseBodyVariables;
951951

952952
CaseStmt(CaseParentKind ParentKind, SourceLoc ItemIntroducerLoc,
953953
ArrayRef<CaseLabelItem> CaseLabelItems, SourceLoc UnknownAttrLoc,
954-
SourceLoc ItemTerminatorLoc, Stmt *Body,
954+
SourceLoc ItemTerminatorLoc, BraceStmt *Body,
955955
Optional<MutableArrayRef<VarDecl *>> CaseBodyVariables,
956956
Optional<bool> Implicit,
957957
NullablePtr<FallthroughStmt> fallthroughStmt);
@@ -960,7 +960,7 @@ class CaseStmt final
960960
static CaseStmt *
961961
create(ASTContext &C, CaseParentKind ParentKind, SourceLoc ItemIntroducerLoc,
962962
ArrayRef<CaseLabelItem> CaseLabelItems, SourceLoc UnknownAttrLoc,
963-
SourceLoc ItemTerminatorLoc, Stmt *Body,
963+
SourceLoc ItemTerminatorLoc, BraceStmt *Body,
964964
Optional<MutableArrayRef<VarDecl *>> CaseBodyVariables,
965965
Optional<bool> Implicit = None,
966966
NullablePtr<FallthroughStmt> fallthroughStmt = nullptr);
@@ -997,8 +997,8 @@ class CaseStmt final
997997

998998
bool hasFallthroughDest() const { return BodyAndHasFallthrough.getInt(); }
999999

1000-
Stmt *getBody() const { return BodyAndHasFallthrough.getPointer(); }
1001-
void setBody(Stmt *body) { BodyAndHasFallthrough.setPointer(body); }
1000+
BraceStmt *getBody() const { return BodyAndHasFallthrough.getPointer(); }
1001+
void setBody(BraceStmt *body) { BodyAndHasFallthrough.setPointer(body); }
10021002

10031003
/// True if the case block declares any patterns with local variable bindings.
10041004
bool hasBoundDecls() const { return CaseBodyVariables.hasValue(); }

lib/AST/ASTWalker.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1631,7 +1631,7 @@ Stmt *Traversal::visitCaseStmt(CaseStmt *S) {
16311631
}
16321632
}
16331633

1634-
if (Stmt *newBody = doIt(S->getBody()))
1634+
if (BraceStmt *newBody = cast_or_null<BraceStmt>(doIt(S->getBody())))
16351635
S->setBody(newBody);
16361636
else
16371637
return nullptr;

lib/AST/Stmt.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ SourceLoc CaseLabelItem::getEndLoc() const {
407407
CaseStmt::CaseStmt(CaseParentKind parentKind, SourceLoc itemIntroducerLoc,
408408
ArrayRef<CaseLabelItem> caseLabelItems,
409409
SourceLoc unknownAttrLoc, SourceLoc itemTerminatorLoc,
410-
Stmt *body,
410+
BraceStmt *body,
411411
Optional<MutableArrayRef<VarDecl *>> caseBodyVariables,
412412
Optional<bool> implicit,
413413
NullablePtr<FallthroughStmt> fallthroughStmt)
@@ -445,7 +445,7 @@ CaseStmt *CaseStmt::create(ASTContext &ctx, CaseParentKind ParentKind,
445445
SourceLoc caseLoc,
446446
ArrayRef<CaseLabelItem> caseLabelItems,
447447
SourceLoc unknownAttrLoc, SourceLoc colonLoc,
448-
Stmt *body,
448+
BraceStmt *body,
449449
Optional<MutableArrayRef<VarDecl *>> caseVarDecls,
450450
Optional<bool> implicit,
451451
NullablePtr<FallthroughStmt> fallthroughStmt) {

lib/Sema/TypeCheckStmt.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1150,7 +1150,7 @@ class StmtChecker : public StmtVisitor<StmtChecker, Stmt*> {
11501150
getASTContext(), caseBlock, limitExhaustivityChecks);
11511151
}
11521152

1153-
Stmt *body = caseBlock->getBody();
1153+
BraceStmt *body = caseBlock->getBody();
11541154
limitExhaustivityChecks |= typeCheckStmt(body);
11551155
caseBlock->setBody(body);
11561156
}

0 commit comments

Comments
 (0)