Skip to content

Commit 4470814

Browse files
committed
[Sema] Recontextualize BreakStmt + ContinueStmt in lazy vars
I don't think this currently matters, but ensure we re-contextualize BreakStmts and ContinueStmts in RecontextualizeClosures since these statements store DeclContexts.
1 parent 34fa48f commit 4470814

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

include/swift/AST/Stmt.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1613,6 +1613,7 @@ class BreakStmt : public Stmt {
16131613
}
16141614

16151615
DeclContext *getDeclContext() const { return DC; }
1616+
void setDeclContext(DeclContext *newDC) { DC = newDC; }
16161617

16171618
static bool classof(const Stmt *S) {
16181619
return S->getKind() == StmtKind::Break;
@@ -1648,6 +1649,7 @@ class ContinueStmt : public Stmt {
16481649
}
16491650

16501651
DeclContext *getDeclContext() const { return DC; }
1652+
void setDeclContext(DeclContext *newDC) { DC = newDC; }
16511653

16521654
static bool classof(const Stmt *S) {
16531655
return S->getKind() == StmtKind::Continue;

lib/Sema/TypeCheckStorage.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1588,6 +1588,12 @@ namespace {
15881588
for (auto *CaseVar : CS->getCaseBodyVariablesOrEmptyArray())
15891589
CaseVar->setDeclContext(NewDC);
15901590
}
1591+
// A few statements store DeclContexts, update them.
1592+
if (auto *BS = dyn_cast<BreakStmt>(S))
1593+
BS->setDeclContext(NewDC);
1594+
if (auto *CS = dyn_cast<ContinueStmt>(S))
1595+
CS->setDeclContext(NewDC);
1596+
15911597
return Action::Continue(S);
15921598
}
15931599

0 commit comments

Comments
 (0)