Skip to content

Commit 4eda042

Browse files
committed
[CSGen] Unify handling of single- and multi-statement closures
Both multi- and single-statement closures now behave the same way when it comes to constraint generation, because the body is opened only once contextual type becomes available or it's impossible to find one e.g. `_ = { 1 }`.
1 parent c6a5f59 commit 4eda042

File tree

1 file changed

+7
-17
lines changed

1 file changed

+7
-17
lines changed

lib/Sema/CSGen.cpp

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3662,20 +3662,16 @@ namespace {
36623662
}
36633663
}
36643664

3665-
// For closures containing only a single expression, the body participates
3666-
// in type checking.
3665+
// Both multi- and single-statement closures now behave the same way
3666+
// when it comes to constraint generation.
36673667
if (auto closure = dyn_cast<ClosureExpr>(expr)) {
36683668
auto &CS = CG.getConstraintSystem();
3669-
if (closure->hasSingleExpressionBody()) {
3670-
auto closureType = CG.visitClosureExpr(closure);
3671-
if (!closureType)
3672-
return {false, nullptr};
3669+
auto closureType = CG.visitClosureExpr(closure);
3670+
if (!closureType)
3671+
return {false, nullptr};
36733672

3674-
CS.setType(expr, closureType);
3675-
return {false, expr};
3676-
}
3677-
3678-
return { true, expr };
3673+
CS.setType(expr, closureType);
3674+
return {false, expr};
36793675
}
36803676

36813677
// Don't visit CoerceExpr with an empty sub expression. They may occur
@@ -3736,12 +3732,6 @@ namespace {
37363732
}
37373733
}
37383734

3739-
if (auto closure = dyn_cast<ClosureExpr>(expr)) {
3740-
if (closure->hasSingleExpressionBody()) {
3741-
return expr;
3742-
}
3743-
}
3744-
37453735
if (auto type = CG.visit(expr)) {
37463736
auto simplifiedType = CS.simplifyType(type);
37473737

0 commit comments

Comments
 (0)