@@ -60,6 +60,9 @@ using namespace swift;
60
60
#define DEBUG_TYPE " TypeCheckStmt"
61
61
62
62
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.
63
66
class ContextualizeClosuresAndMacros : public ASTWalker {
64
67
DeclContext *ParentDC;
65
68
public:
@@ -70,16 +73,10 @@ namespace {
70
73
}
71
74
72
75
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
78
76
if (auto CE = dyn_cast<AutoClosureExpr>(E)) {
79
77
CE->setParent (ParentDC);
80
78
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.
83
80
auto oldParentDC = ParentDC;
84
81
ParentDC = CE;
85
82
CE->getBody ()->walk (*this );
@@ -103,13 +100,12 @@ namespace {
103
100
}
104
101
}
105
102
106
- // Explicit closures start their own sequence.
107
103
if (auto CE = dyn_cast<ClosureExpr>(E)) {
108
104
CE->setParent (ParentDC);
109
105
110
106
// 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.
113
109
if (!CE->isSeparatelyTypeChecked ())
114
110
CE->getBody ()->walk (ContextualizeClosuresAndMacros (CE));
115
111
0 commit comments