@@ -45,18 +45,20 @@ using namespace inference;
45
45
Type ConstraintSystem::openUnboundGenericType (GenericTypeDecl *decl,
46
46
Type parentTy,
47
47
ConstraintLocatorBuilder locator,
48
- bool isTypeResolution) {
48
+ bool isTypeResolution,
49
+ PreparedOverload *preparedOverload) {
49
50
if (parentTy) {
50
- parentTy = replaceInferableTypesWithTypeVars (parentTy, locator);
51
+ parentTy = replaceInferableTypesWithTypeVars (
52
+ parentTy, locator, preparedOverload);
51
53
}
52
54
53
55
// Open up the generic type.
54
56
SmallVector<OpenedType, 4 > replacements;
55
57
openGeneric (decl->getDeclContext (), decl->getGenericSignature (), locator,
56
- replacements, /* preparedOverload= */ nullptr );
58
+ replacements, preparedOverload);
57
59
58
60
// FIXME: Get rid of fixmeAllowDuplicates.
59
- recordOpenedTypes (locator, replacements, /* preparedOverload= */ nullptr ,
61
+ recordOpenedTypes (locator, replacements, preparedOverload,
60
62
/* fixmeAllowDuplicates=*/ true );
61
63
62
64
if (parentTy) {
@@ -84,7 +86,7 @@ Type ConstraintSystem::openUnboundGenericType(GenericTypeDecl *decl,
84
86
continue ;
85
87
86
88
addConstraint (ConstraintKind::Bind, pair.second , found->second ,
87
- locator);
89
+ locator, /* isFavored= */ false , preparedOverload );
88
90
}
89
91
}
90
92
@@ -197,34 +199,35 @@ static void checkNestedTypeConstraints(ConstraintSystem &cs, Type type,
197
199
}
198
200
199
201
Type ConstraintSystem::replaceInferableTypesWithTypeVars (
200
- Type type, ConstraintLocatorBuilder locator) {
202
+ Type type, ConstraintLocatorBuilder locator,
203
+ PreparedOverload *preparedOverload) {
201
204
if (!type->hasUnboundGenericType () && !type->hasPlaceholder ())
202
205
return type;
203
206
207
+ auto flags = TVO_CanBindToNoEscape | TVO_PrefersSubtypeBinding | TVO_CanBindToHole;
208
+
204
209
type = type.transformRec ([&](Type type) -> std::optional<Type> {
205
210
if (auto unbound = type->getAs <UnboundGenericType>()) {
206
211
return openUnboundGenericType (unbound->getDecl (), unbound->getParent (),
207
- locator, /* isTypeResolution=*/ false );
212
+ locator, /* isTypeResolution=*/ false ,
213
+ preparedOverload);
208
214
} else if (auto *placeholderTy = type->getAs <PlaceholderType>()) {
209
215
if (auto *typeRepr =
210
216
placeholderTy->getOriginator ().dyn_cast <TypeRepr *>()) {
211
217
if (isa<PlaceholderTypeRepr>(typeRepr)) {
212
- return Type (createTypeVariable (
213
- getConstraintLocator (locator,
214
- LocatorPathElt::PlaceholderType (typeRepr)),
215
- TVO_CanBindToNoEscape | TVO_PrefersSubtypeBinding |
216
- TVO_CanBindToHole));
218
+ return Type (
219
+ createTypeVariable (
220
+ getConstraintLocator (locator, LocatorPathElt::PlaceholderType (typeRepr)),
221
+ flags, preparedOverload));
217
222
}
218
- } else if (auto *var =
219
- placeholderTy->getOriginator ().dyn_cast <VarDecl *>()) {
223
+ } else if (auto *var = placeholderTy->getOriginator ().dyn_cast <VarDecl *>()) {
220
224
if (var->getName ().hasDollarPrefix ()) {
221
225
auto *repr =
222
226
new (type->getASTContext ()) PlaceholderTypeRepr (var->getLoc ());
223
- return Type (createTypeVariable (
224
- getConstraintLocator (locator,
225
- LocatorPathElt::PlaceholderType (repr)),
226
- TVO_CanBindToNoEscape | TVO_PrefersSubtypeBinding |
227
- TVO_CanBindToHole));
227
+ return Type (
228
+ createTypeVariable (
229
+ getConstraintLocator (locator, LocatorPathElt::PlaceholderType (repr)),
230
+ flags, preparedOverload));
228
231
}
229
232
}
230
233
}
@@ -1085,7 +1088,7 @@ ConstraintSystem::getTypeOfReference(ValueDecl *value,
1085
1088
checkNestedTypeConstraints (*this , type, locator, preparedOverload);
1086
1089
1087
1090
// Convert any placeholder types and open generics.
1088
- type = replaceInferableTypesWithTypeVars (type, locator);
1091
+ type = replaceInferableTypesWithTypeVars (type, locator, preparedOverload );
1089
1092
1090
1093
// Module types are not wrapped in metatypes.
1091
1094
if (type->is <ModuleType>())
@@ -1629,7 +1632,8 @@ DeclReferenceType ConstraintSystem::getTypeOfMemberReference(
1629
1632
checkNestedTypeConstraints (*this , memberTy, locator, preparedOverload);
1630
1633
1631
1634
// Convert any placeholders and open any generics.
1632
- memberTy = replaceInferableTypesWithTypeVars (memberTy, locator);
1635
+ memberTy = replaceInferableTypesWithTypeVars (
1636
+ memberTy, locator, preparedOverload);
1633
1637
1634
1638
// Wrap it in a metatype.
1635
1639
memberTy = MetatypeType::get (memberTy);
0 commit comments