@@ -1345,33 +1345,35 @@ namespace {
1345
1345
// / Perform prechecking of a ClosureExpr before we dive into it. This returns
1346
1346
// / true when we want the body to be considered part of this larger expression.
1347
1347
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
-
1361
1348
// 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.
1363
1352
auto *body = closure->getBody ();
1364
1353
if (body->getNumElements () == 1 ) {
1365
1354
if (auto *S = body->getLastElement ().dyn_cast <Stmt *>()) {
1366
1355
if (S->mayProduceSingleValue (Ctx)) {
1367
1356
auto *SVE = SingleValueStmtExpr::createWithWrappedBranches (
1368
- Ctx, S, DC , /* mustBeExpr*/ false );
1357
+ Ctx, S, /* DC */ closure , /* mustBeExpr*/ false );
1369
1358
auto *RS = new (Ctx) ReturnStmt (SourceLoc (), SVE);
1370
1359
body->setLastElement (RS);
1371
1360
closure->setBody (body, /* isSingleExpression*/ true );
1372
1361
}
1373
1362
}
1374
1363
}
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;
1375
1377
return true ;
1376
1378
}
1377
1379
0 commit comments