@@ -572,8 +572,9 @@ namespace {
572572 return false ;
573573
574574 return isFavoredParamAndArg (CS, paramTy, argTy) &&
575- hasContextuallyFavorableResultType (fnTy,
576- CS.getContextualType (expr));
575+ hasContextuallyFavorableResultType (
576+ fnTy,
577+ CS.getContextualType (expr, /* forConstraint=*/ false ));
577578 };
578579
579580 favorCallOverloads (expr, CS, isFavoredDecl);
@@ -722,7 +723,7 @@ namespace {
722723 auto firstParamTy = params[0 ].getOldType ();
723724 auto secondParamTy = params[1 ].getOldType ();
724725
725- auto contextualTy = CS.getContextualType (expr);
726+ auto contextualTy = CS.getContextualType (expr, /* forConstraint= */ false );
726727
727728 // Avoid favoring overloads that would require narrowing conversion
728729 // to match the arguments.
@@ -1709,7 +1710,7 @@ namespace {
17091710 return Type ();
17101711
17111712 auto locator = CS.getConstraintLocator (expr);
1712- auto contextualType = CS.getContextualType (expr);
1713+ auto contextualType = CS.getContextualType (expr, /* forConstraint= */ false );
17131714 auto contextualPurpose = CS.getContextualTypePurpose (expr);
17141715
17151716 auto joinElementTypes = [&](Optional<Type> elementType) {
@@ -1837,7 +1838,7 @@ namespace {
18371838 auto valueAssocTy = dictionaryProto->getAssociatedType (C.Id_Value );
18381839
18391840 auto locator = CS.getConstraintLocator (expr);
1840- auto contextualType = CS.getContextualType (expr);
1841+ auto contextualType = CS.getContextualType (expr, /* forConstraint= */ false );
18411842 auto contextualPurpose = CS.getContextualTypePurpose (expr);
18421843
18431844 // If a contextual type exists for this expression and is a dictionary
@@ -1904,7 +1905,7 @@ namespace {
19041905
19051906 // If no contextual type is present, Merge equivalence classes of key
19061907 // and value types as necessary.
1907- if (!CS.getContextualType (expr)) {
1908+ if (!CS.getContextualType (expr, /* forConstraint= */ false )) {
19081909 for (auto element1 : expr->getElements ()) {
19091910 for (auto element2 : expr->getElements ()) {
19101911 if (element1 == element2)
@@ -2068,7 +2069,13 @@ namespace {
20682069 return resolvedTy;
20692070 }
20702071
2071- if (auto contextualType = CS.getContextualType (closure)) {
2072+ // Because we are only pulling out the result type from the contextual
2073+ // type, we avoid prematurely converting any inferrable types by setting
2074+ // forConstraint=false. Later on in inferClosureType we call
2075+ // replaceInferableTypesWithTypeVars before returning to ensure we don't
2076+ // introduce any placeholders into the constraint system.
2077+ if (auto contextualType =
2078+ CS.getContextualType (closure, /* forConstraint=*/ false )) {
20722079 if (auto fnType = contextualType->getAs <FunctionType>())
20732080 return fnType->getResult ();
20742081 }
0 commit comments