Skip to content

Commit a79e7b5

Browse files
committed
[Sema] Convert placeholder types in expression conversion types
1 parent fbb78cd commit a79e7b5

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

lib/Sema/CSGen.cpp

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3802,16 +3802,28 @@ bool ConstraintSystem::generateConstraints(
38023802
// Determine whether we know more about the contextual type.
38033803
ContextualTypePurpose ctp = target.getExprContextualTypePurpose();
38043804
bool isOpaqueReturnType = target.infersOpaqueReturnType();
3805+
auto *convertTypeLocator =
3806+
getConstraintLocator(expr, LocatorPathElt::ContextualType());
38053807

3806-
// Substitute type variables in for unresolved types.
3808+
// Substitute type variables in for placeholder types (and unresolved
3809+
// types, if allowed).
38073810
if (allowFreeTypeVariables == FreeTypeVariableBinding::UnresolvedType) {
3808-
auto *convertTypeLocator =
3809-
getConstraintLocator(expr, LocatorPathElt::ContextualType());
3810-
38113811
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);
38153827
}
38163828
return type;
38173829
});

0 commit comments

Comments
 (0)