Skip to content

Commit 691b3c6

Browse files
author
David Ungar
committed
When delayed parsing a Decl in a closure body, add it to the body.
1 parent 6577e68 commit 691b3c6

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

lib/Parse/ParseDecl.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3256,9 +3256,17 @@ void Parser::parseDeclDelayed() {
32563256
} else if (auto *ED = dyn_cast<ExtensionDecl>(parent)) {
32573257
ED->addMember(D);
32583258
} else if (auto *SF = dyn_cast<SourceFile>(parent)) {
3259-
// FIXME: unify notification to ASTSourceFileScope with addMember
3260-
// mechanism used above
32613259
SF->Decls.push_back(D);
3260+
} else if (auto *CE = dyn_cast<ClosureExpr>(parent)) {
3261+
// Replace the closure body with one including the new Decl.
3262+
auto *body = CE->getBody();
3263+
SmallVector<ASTNode, 8> Elts(body->getElements().begin(),
3264+
body->getElements().end());
3265+
Elts.push_back(ASTNode(D));
3266+
auto *newBody =
3267+
BraceStmt::create(Context, body->getLBraceLoc(), Elts,
3268+
body->getRBraceLoc(), body->isImplicit());
3269+
CE->setBody(newBody, false);
32623270
}
32633271
}
32643272
});

0 commit comments

Comments
 (0)