@@ -7222,6 +7222,24 @@ bool ConstraintSystem::resolveClosure(TypeVariableType *typeVar,
72227222 auto *closure = castToExpr<ClosureExpr>(closureLocator->getAnchor ());
72237223 auto *inferredClosureType = getClosureType (closure);
72247224
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+
72257243 auto *paramList = closure->getParameters ();
72267244 SmallVector<AnyFunctionType::Param, 4 > parameters;
72277245 for (unsigned i = 0 , n = paramList->size (); i != n; ++i) {
@@ -7235,9 +7253,6 @@ bool ConstraintSystem::resolveClosure(TypeVariableType *typeVar,
72357253 }
72367254
72377255 Type internalType;
7238-
7239- bool oneWayConstraints =
7240- getASTContext ().TypeCheckerOpts .EnableOneWayClosureParameters ;
72417256 if (paramList->get (i)->getTypeRepr ()) {
72427257 // Internal type is the type used in the body of the closure,
72437258 // so "external" type translates to it as follows:
@@ -7288,17 +7303,12 @@ bool ConstraintSystem::resolveClosure(TypeVariableType *typeVar,
72887303 inferredClosureType->getExtInfo ());
72897304 assignFixedType (typeVar, closureType, closureLocator);
72907305
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 ();
73027312 }
73037313 }
73047314
0 commit comments