@@ -564,8 +564,9 @@ namespace {
564
564
return false;
565
565
566
566
return isFavoredParamAndArg(CS, paramTy, argTy) &&
567
- hasContextuallyFavorableResultType (fnTy,
568
- CS.getContextualType (expr));
567
+ hasContextuallyFavorableResultType(
568
+ fnTy,
569
+ CS.getContextualType(expr, /*forConstraint=*/false));
569
570
};
570
571
571
572
favorCallOverloads(expr, CS, isFavoredDecl);
@@ -714,7 +715,7 @@ namespace {
714
715
auto firstParamTy = params[0].getOldType();
715
716
auto secondParamTy = params[1].getOldType();
716
717
717
- auto contextualTy = CS.getContextualType (expr);
718
+ auto contextualTy = CS.getContextualType(expr, /*forConstraint=*/false );
718
719
719
720
// Avoid favoring overloads that would require narrowing conversion
720
721
// to match the arguments.
@@ -1709,7 +1710,7 @@ namespace {
1709
1710
return Type();
1710
1711
1711
1712
auto locator = CS.getConstraintLocator(expr);
1712
- auto contextualType = CS.getContextualType (expr);
1713
+ auto contextualType = CS.getContextualType(expr, /*forConstraint=*/false );
1713
1714
auto contextualPurpose = CS.getContextualTypePurpose(expr);
1714
1715
1715
1716
auto joinElementTypes = [&](Optional<Type> elementType) {
@@ -1837,7 +1838,7 @@ namespace {
1837
1838
auto valueAssocTy = dictionaryProto->getAssociatedType(C.Id_Value);
1838
1839
1839
1840
auto locator = CS.getConstraintLocator(expr);
1840
- auto contextualType = CS.getContextualType (expr);
1841
+ auto contextualType = CS.getContextualType(expr, /*forConstraint=*/false );
1841
1842
auto contextualPurpose = CS.getContextualTypePurpose(expr);
1842
1843
1843
1844
// If a contextual type exists for this expression and is a dictionary
@@ -1904,7 +1905,7 @@ namespace {
1904
1905
1905
1906
// If no contextual type is present, Merge equivalence classes of key
1906
1907
// and value types as necessary.
1907
- if (!CS.getContextualType (expr)) {
1908
+ if (!CS.getContextualType(expr, /*forConstraint=*/false )) {
1908
1909
for (auto element1 : expr->getElements()) {
1909
1910
for (auto element2 : expr->getElements()) {
1910
1911
if (element1 == element2)
@@ -2068,7 +2069,13 @@ namespace {
2068
2069
return resolvedTy;
2069
2070
}
2070
2071
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)) {
2072
2079
if (auto fnType = contextualType->getAs<FunctionType>())
2073
2080
return fnType->getResult();
2074
2081
}
0 commit comments