@@ -403,9 +403,21 @@ getStructuralTypeContext(const Solution &solution, ConstraintLocator *locator) {
403
403
return std::make_tuple (contextualTypeElt->getPurpose (), exprType,
404
404
contextualType);
405
405
} else if (auto argApplyInfo = solution.getFunctionArgApplyInfo (locator)) {
406
- return std::make_tuple (CTP_CallArgument,
407
- argApplyInfo->getArgType (),
408
- argApplyInfo->getParamType ());
406
+ Type fromType = argApplyInfo->getArgType ();
407
+ Type toType = argApplyInfo->getParamType ();
408
+ // In case locator points to the function result we want the
409
+ // argument and param function types result.
410
+ if (locator->isLastElement <LocatorPathElt::FunctionResult>()) {
411
+ auto fromFnType = fromType->getAs <FunctionType>();
412
+ auto toFnType = toType->getAs <FunctionType>();
413
+ if (fromFnType && toFnType) {
414
+ auto &cs = solution.getConstraintSystem ();
415
+ return std::make_tuple (
416
+ cs.getContextualTypePurpose (locator->getAnchor ()),
417
+ fromFnType->getResult (), toFnType->getResult ());
418
+ }
419
+ }
420
+ return std::make_tuple (CTP_CallArgument, fromType, toType);
409
421
} else if (auto *coerceExpr = getAsExpr<CoerceExpr>(locator->getAnchor ())) {
410
422
return std::make_tuple (CTP_CoerceOperand,
411
423
solution.getType (coerceExpr->getSubExpr ()),
0 commit comments