@@ -572,8 +572,9 @@ namespace {
572
572
return false ;
573
573
574
574
return isFavoredParamAndArg (CS, paramTy, argTy) &&
575
- hasContextuallyFavorableResultType (fnTy,
576
- CS.getContextualType (expr));
575
+ hasContextuallyFavorableResultType (
576
+ fnTy,
577
+ CS.getContextualType (expr, /* forConstraint=*/ false ));
577
578
};
578
579
579
580
favorCallOverloads (expr, CS, isFavoredDecl);
@@ -722,7 +723,7 @@ namespace {
722
723
auto firstParamTy = params[0 ].getOldType ();
723
724
auto secondParamTy = params[1 ].getOldType ();
724
725
725
- auto contextualTy = CS.getContextualType (expr);
726
+ auto contextualTy = CS.getContextualType (expr, /* forConstraint= */ false );
726
727
727
728
// Avoid favoring overloads that would require narrowing conversion
728
729
// 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