@@ -1088,27 +1088,27 @@ bool BindingSet::favoredOverConjunction(Constraint *conjunction) const {
1088
1088
if (!(contextualType && contextualType->is <FunctionType>()))
1089
1089
return true ;
1090
1090
1091
- auto *contextualFnType = contextualType->castTo <FunctionType>();
1092
- auto resultType = contextualFnType->getResult ();
1093
- if (resultType->hasTypeVariable ()) {
1094
- auto *typeVar = resultType->getAs <TypeVariableType>();
1095
- // If contextual result type is represented by an opaque type,
1096
- // it's a strong indication that body is self-contained, otherwise
1097
- // closure might rely on external types flowing into the body for
1098
- // disambiguation of `build{Partial}Block` or `buildFinalResult`
1099
- // calls.
1100
- if (!(typeVar && typeVar->getImpl ().isOpaqueType ()))
1101
- return true ;
1091
+ auto *contextualFnType =
1092
+ CS.simplifyType (contextualType)->castTo <FunctionType>();
1093
+ {
1094
+ auto resultType = contextualFnType->getResult ();
1095
+ if (resultType->hasTypeVariable ()) {
1096
+ auto *typeVar = resultType->getAs <TypeVariableType>();
1097
+ // If contextual result type is represented by an opaque type,
1098
+ // it's a strong indication that body is self-contained, otherwise
1099
+ // closure might rely on external types flowing into the body for
1100
+ // disambiguation of `build{Partial}Block` or `buildFinalResult`
1101
+ // calls.
1102
+ if (!(typeVar && typeVar->getImpl ().isOpaqueType ()))
1103
+ return true ;
1104
+ }
1102
1105
}
1103
1106
1104
- auto *closureType = CS.getClosureType (closure);
1105
- // If closure has parameters, it has to be delayed to give
1106
- // them a chance to be resolved.
1107
- //
1108
- // Note: Since we have access to a contextual type here it should be
1109
- // possible to transform this check into - if some of the parameters
1110
- // have type variables (that means not-yet-resolved generic parameters).
1111
- if (closureType->getNumParams () != 0 )
1107
+ // If some of the closure parameters are unresolved, the conjunction
1108
+ // has to be delayed to give them a chance to be inferred.
1109
+ if (llvm::any_of (contextualFnType->getParams (), [](const auto ¶m) {
1110
+ return param.getPlainType ()->hasTypeVariable ();
1111
+ }))
1112
1112
return true ;
1113
1113
1114
1114
// If conjunction references a single type variable (closure itself)
0 commit comments