@@ -3802,16 +3802,28 @@ bool ConstraintSystem::generateConstraints(
3802
3802
// Determine whether we know more about the contextual type.
3803
3803
ContextualTypePurpose ctp = target.getExprContextualTypePurpose ();
3804
3804
bool isOpaqueReturnType = target.infersOpaqueReturnType ();
3805
+ auto *convertTypeLocator =
3806
+ getConstraintLocator (expr, LocatorPathElt::ContextualType ());
3805
3807
3806
- // Substitute type variables in for unresolved types.
3808
+ // Substitute type variables in for placeholder types (and unresolved
3809
+ // types, if allowed).
3807
3810
if (allowFreeTypeVariables == FreeTypeVariableBinding::UnresolvedType) {
3808
- auto *convertTypeLocator =
3809
- getConstraintLocator (expr, LocatorPathElt::ContextualType ());
3810
-
3811
3811
convertType = convertType.transform ([&](Type type) -> Type {
3812
- if (type->is <UnresolvedType>()) {
3813
- return createTypeVariable (
3814
- convertTypeLocator, TVO_CanBindToNoEscape);
3812
+ if (type->is <UnresolvedType>() || type->is <PlaceholderType>()) {
3813
+ return createTypeVariable (convertTypeLocator,
3814
+ TVO_CanBindToNoEscape |
3815
+ TVO_PrefersSubtypeBinding |
3816
+ TVO_CanBindToHole);
3817
+ }
3818
+ return type;
3819
+ });
3820
+ } else {
3821
+ convertType = convertType.transform ([&](Type type) -> Type {
3822
+ if (type->is <PlaceholderType>()) {
3823
+ return createTypeVariable (convertTypeLocator,
3824
+ TVO_CanBindToNoEscape |
3825
+ TVO_PrefersSubtypeBinding |
3826
+ TVO_CanBindToHole);
3815
3827
}
3816
3828
return type;
3817
3829
});
0 commit comments