@@ -907,24 +907,34 @@ class SyntacticElementConstraintGenerator
907
907
void visitBraceStmt (BraceStmt *braceStmt) {
908
908
auto &ctx = cs.getASTContext ();
909
909
910
- if (auto closure = cast<ClosureExpr>(context.getAsAbstractClosureExpr ().getPtrOrNull ()); context.getBody () == braceStmt) {
911
- // If this closure has an empty body and no explicit result type
912
- // let's bind result type to `Void` since that's the only type empty body
913
- // can produce. Otherwise, if (multi-statement) closure doesn't have
914
- // an explicit result (no `return` statements) let's default it to `Void`.
915
- if (!constraints::hasExplicitResult (closure)) {
916
- auto constraintKind =
917
- (closure->hasEmptyBody () && !closure->hasExplicitResultType ())
918
- ? ConstraintKind::Bind
919
- : ConstraintKind::Defaultable;
920
-
921
- cs.addConstraint (
922
- constraintKind, cs.getClosureType (closure)->getResult (),
923
- ctx.TheEmptyTupleType ,
924
- cs.getConstraintLocator (closure, ConstraintLocator::ClosureResult));
910
+ auto addResultDefault = [&](ClosureExpr *closure) {
911
+ if (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
914
+ // body can produce. Otherwise, if (multi-statement) closure doesn't
915
+ // have an explicit result (no `return` statements) let's default it to
916
+ // `Void`.
917
+ if (!constraints::hasExplicitResult (closure)) {
918
+ auto constraintKind =
919
+ (closure->hasEmptyBody () && !closure->hasExplicitResultType ())
920
+ ? ConstraintKind::Bind
921
+ : ConstraintKind::Defaultable;
922
+
923
+ cs.addConstraint (constraintKind,
924
+ cs.getClosureType (closure)->getResult (),
925
+ ctx.TheEmptyTupleType ,
926
+ cs.getConstraintLocator (
927
+ closure, ConstraintLocator::ClosureResult));
928
+ }
925
929
}
926
- if (!cs.participatesInInference (closure))
930
+ };
931
+
932
+ if (auto closure = cast<ClosureExpr>(
933
+ context.getAsAbstractClosureExpr ().getPtrOrNull ())) {
934
+ if (!cs.participatesInInference (closure)) {
935
+ addResultDefault (closure);
927
936
return ;
937
+ }
928
938
}
929
939
930
940
if (context.isSingleExpressionClosure (cs)) {
@@ -941,6 +951,10 @@ class SyntacticElementConstraintGenerator
941
951
visitDecl (node.get <Decl *>());
942
952
}
943
953
}
954
+ if (!hadError)
955
+ addResultDefault (cast<ClosureExpr>(
956
+ context.getAsAbstractClosureExpr ().getPtrOrNull ()));
957
+
944
958
return ;
945
959
}
946
960
@@ -974,6 +988,10 @@ class SyntacticElementConstraintGenerator
974
988
/* contextualInfo=*/ {}, isDiscarded));
975
989
}
976
990
991
+ if (!hadError)
992
+ addResultDefault (
993
+ cast<ClosureExpr>(context.getAsAbstractClosureExpr ().getPtrOrNull ()));
994
+
977
995
createConjunction (cs, elements, locator);
978
996
}
979
997
0 commit comments