@@ -7222,6 +7222,24 @@ bool ConstraintSystem::resolveClosure(TypeVariableType *typeVar,
7222
7222
auto *closure = castToExpr<ClosureExpr>(closureLocator->getAnchor ());
7223
7223
auto *inferredClosureType = getClosureType (closure);
7224
7224
7225
+ // Determine whether a function builder will be applied.
7226
+ Type functionBuilderType;
7227
+ ConstraintLocator *calleeLocator = nullptr ;
7228
+ if (auto last = locator.last ()) {
7229
+ if (auto argToParam = last->getAs <LocatorPathElt::ApplyArgToParam>()) {
7230
+ calleeLocator = getCalleeLocator (getConstraintLocator (locator));
7231
+ functionBuilderType = getFunctionBuilderTypeFor (
7232
+ *this , argToParam->getParamIdx (), calleeLocator);
7233
+ }
7234
+ }
7235
+
7236
+ // Determine whether to introduce one-way constraints between the parameter's
7237
+ // type as seen in the body of the closure and the external parameter
7238
+ // type.
7239
+ bool oneWayConstraints =
7240
+ getASTContext ().TypeCheckerOpts .EnableOneWayClosureParameters ||
7241
+ functionBuilderType;
7242
+
7225
7243
auto *paramList = closure->getParameters ();
7226
7244
SmallVector<AnyFunctionType::Param, 4 > parameters;
7227
7245
for (unsigned i = 0 , n = paramList->size (); i != n; ++i) {
@@ -7235,9 +7253,6 @@ bool ConstraintSystem::resolveClosure(TypeVariableType *typeVar,
7235
7253
}
7236
7254
7237
7255
Type internalType;
7238
-
7239
- bool oneWayConstraints =
7240
- getASTContext ().TypeCheckerOpts .EnableOneWayClosureParameters ;
7241
7256
if (paramList->get (i)->getTypeRepr ()) {
7242
7257
// Internal type is the type used in the body of the closure,
7243
7258
// so "external" type translates to it as follows:
@@ -7288,17 +7303,12 @@ bool ConstraintSystem::resolveClosure(TypeVariableType *typeVar,
7288
7303
inferredClosureType->getExtInfo ());
7289
7304
assignFixedType (typeVar, closureType, closureLocator);
7290
7305
7291
- if (auto last = locator.last ()) {
7292
- if (auto argToParam = last->getAs <LocatorPathElt::ApplyArgToParam>()) {
7293
- auto *calleeLocator = getCalleeLocator (getConstraintLocator (locator));
7294
- if (auto functionBuilderType = getFunctionBuilderTypeFor (
7295
- *this , argToParam->getParamIdx (), calleeLocator)) {
7296
- if (auto result = matchFunctionBuilder (
7297
- closure, functionBuilderType, closureType->getResult (),
7298
- ConstraintKind::Conversion, calleeLocator, locator)) {
7299
- return result->isSuccess ();
7300
- }
7301
- }
7306
+ // If there is a function builder to apply, do so now.
7307
+ if (functionBuilderType) {
7308
+ if (auto result = matchFunctionBuilder (
7309
+ closure, functionBuilderType, closureType->getResult (),
7310
+ ConstraintKind::Conversion, calleeLocator, locator)) {
7311
+ return result->isSuccess ();
7302
7312
}
7303
7313
}
7304
7314
0 commit comments