@@ -905,6 +905,27 @@ class SyntacticElementConstraintGenerator
905
905
}
906
906
907
907
void visitBraceStmt (BraceStmt *braceStmt) {
908
+ auto &ctx = cs.getASTContext ();
909
+
910
+ if (auto closure = cast<ClosureExpr>(context.getAbstractClosureExpr ());
911
+ context.getBody () == braceStmt) {
912
+ // If this closure has an empty body and no explicit result type
913
+ // let's bind result type to `Void` since that's the only type empty body
914
+ // can produce. Otherwise, if (multi-statement) closure doesn't have
915
+ // an explicit result (no `return` statements) let's default it to `Void`.
916
+ if (!constraints::hasExplicitResult (closure)) {
917
+ auto constraintKind =
918
+ (closure->hasEmptyBody () && !closure->hasExplicitResultType ())
919
+ ? ConstraintKind::Bind
920
+ : ConstraintKind::Defaultable;
921
+
922
+ cs.addConstraint (
923
+ constraintKind, cs.getClosureType (closure)->getResult (),
924
+ ctx.TheEmptyTupleType ,
925
+ cs.getConstraintLocator (closure, ConstraintLocator::ClosureResult));
926
+ }
927
+ }
928
+
908
929
if (context.isSingleExpressionClosure (cs)) {
909
930
for (auto node : braceStmt->getElements ()) {
910
931
if (auto expr = node.dyn_cast <Expr *>()) {
@@ -922,8 +943,6 @@ class SyntacticElementConstraintGenerator
922
943
return ;
923
944
}
924
945
925
- auto &ctx = cs.getASTContext ();
926
-
927
946
if (isChildOf (StmtKind::Case)) {
928
947
auto *caseStmt = cast<CaseStmt>(
929
948
locator->castLastElementTo <LocatorPathElt::SyntacticElement>()
@@ -1131,8 +1150,6 @@ bool ConstraintSystem::generateConstraints(AnyFunctionRef fn, BraceStmt *body) {
1131
1150
auto closure = cast<ClosureExpr>(fn.getAbstractClosureExpr ());
1132
1151
locator = getConstraintLocator (closure);
1133
1152
1134
- auto &ctx = closure->getASTContext ();
1135
-
1136
1153
if (participatesInInference (closure)) {
1137
1154
SyntacticElementConstraintGenerator generator (
1138
1155
*this , closure, getConstraintLocator (closure));
@@ -1143,22 +1160,6 @@ bool ConstraintSystem::generateConstraints(AnyFunctionRef fn, BraceStmt *body) {
1143
1160
return generator.hadError ;
1144
1161
}
1145
1162
1146
- // If this closure has an empty body and no explicit result type
1147
- // let's bind result type to `Void` since that's the only type empty body
1148
- // can produce. Otherwise, if (multi-statement) closure doesn't have
1149
- // an explicit result (no `return` statements) let's default it to `Void`.
1150
- if (!hasExplicitResult (closure)) {
1151
- auto constraintKind =
1152
- (closure->hasEmptyBody () && !closure->hasExplicitResultType ())
1153
- ? ConstraintKind::Bind
1154
- : ConstraintKind::Defaultable;
1155
-
1156
- addConstraint (
1157
- constraintKind, getClosureType (closure)->getResult (),
1158
- ctx.TheEmptyTupleType ,
1159
- getConstraintLocator (closure, ConstraintLocator::ClosureResult));
1160
- }
1161
-
1162
1163
return false ;
1163
1164
}
1164
1165
0 commit comments