Skip to content

Commit 509346d

Browse files
committed
ff
1 parent ee74596 commit 509346d

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

lib/Sema/PreCheckExpr.cpp

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1345,33 +1345,35 @@ namespace {
13451345
/// Perform prechecking of a ClosureExpr before we dive into it. This returns
13461346
/// true when we want the body to be considered part of this larger expression.
13471347
bool PreCheckExpression::walkToClosureExprPre(ClosureExpr *closure) {
1348-
// If we won't be checking the body of the closure, don't walk into it here.
1349-
if (!closure->hasSingleExpressionBody()) {
1350-
if (LeaveClosureBodiesUnchecked)
1351-
return false;
1352-
}
1353-
1354-
// Update the current DeclContext to be the closure we're about to
1355-
// recurse into.
1356-
assert((closure->getParent() == DC ||
1357-
closure->getParent()->isChildContextOf(DC)) &&
1358-
"Decl context isn't correct");
1359-
DC = closure;
1360-
13611348
// If we have a single statement that can become an expression, turn it
1362-
// into an expression now.
1349+
// into an expression now. This needs to happen before we check
1350+
// LeaveClosureBodiesUnchecked, as the closure may become a single expression
1351+
// closure.
13631352
auto *body = closure->getBody();
13641353
if (body->getNumElements() == 1) {
13651354
if (auto *S = body->getLastElement().dyn_cast<Stmt *>()) {
13661355
if (S->mayProduceSingleValue(Ctx)) {
13671356
auto *SVE = SingleValueStmtExpr::createWithWrappedBranches(
1368-
Ctx, S, DC, /*mustBeExpr*/ false);
1357+
Ctx, S, /*DC*/ closure, /*mustBeExpr*/ false);
13691358
auto *RS = new (Ctx) ReturnStmt(SourceLoc(), SVE);
13701359
body->setLastElement(RS);
13711360
closure->setBody(body, /*isSingleExpression*/ true);
13721361
}
13731362
}
13741363
}
1364+
1365+
// If we won't be checking the body of the closure, don't walk into it here.
1366+
if (!closure->hasSingleExpressionBody()) {
1367+
if (LeaveClosureBodiesUnchecked)
1368+
return false;
1369+
}
1370+
1371+
// Update the current DeclContext to be the closure we're about to
1372+
// recurse into.
1373+
assert((closure->getParent() == DC ||
1374+
closure->getParent()->isChildContextOf(DC)) &&
1375+
"Decl context isn't correct");
1376+
DC = closure;
13751377
return true;
13761378
}
13771379

0 commit comments

Comments
 (0)