Skip to content

Commit 78d70ab

Browse files
committed
Sema: Update comments on ContextualizeClosuresAndMacros
The discriminator assignment has since been split off into a separate thing, so all this does now is re-parent children of autoclosures.
1 parent dbc8c4b commit 78d70ab

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

lib/Sema/TypeCheckStmt.cpp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ using namespace swift;
6060
#define DEBUG_TYPE "TypeCheckStmt"
6161

6262
namespace {
63+
/// After forming autoclosures, we must re-parent any closure expressions
64+
/// nested inside the autoclosure, because the autoclosure introduces a new
65+
/// DeclContext.
6366
class ContextualizeClosuresAndMacros : public ASTWalker {
6467
DeclContext *ParentDC;
6568
public:
@@ -70,16 +73,10 @@ namespace {
7073
}
7174

7275
PreWalkResult<Expr *> walkToExprPre(Expr *E) override {
73-
// Autoclosures need to be numbered and potentially reparented.
74-
// Reparenting is required with:
75-
// - nested autoclosures, because the inner autoclosure will be
76-
// parented to the outer context, not the outer autoclosure
77-
// - non-local initializers
7876
if (auto CE = dyn_cast<AutoClosureExpr>(E)) {
7977
CE->setParent(ParentDC);
8078

81-
// Recurse into the autoclosure body using the same sequence,
82-
// but parenting to the autoclosure instead of the outer closure.
79+
// Recurse into the autoclosure body with the new ParentDC.
8380
auto oldParentDC = ParentDC;
8481
ParentDC = CE;
8582
CE->getBody()->walk(*this);
@@ -103,13 +100,12 @@ namespace {
103100
}
104101
}
105102

106-
// Explicit closures start their own sequence.
107103
if (auto CE = dyn_cast<ClosureExpr>(E)) {
108104
CE->setParent(ParentDC);
109105

110106
// If the closure was type checked within its enclosing context,
111-
// we need to walk into it with a new sequence.
112-
// Otherwise, it'll have been separately type-checked.
107+
// we need to walk into it. Otherwise, it'll have been separately
108+
// type-checked.
113109
if (!CE->isSeparatelyTypeChecked())
114110
CE->getBody()->walk(ContextualizeClosuresAndMacros(CE));
115111

0 commit comments

Comments
 (0)