@@ -4675,6 +4675,12 @@ ConstraintSystem::matchTypesBindTypeVar(
4675
4675
: getTypeMatchFailure(locator);
4676
4676
}
4677
4677
4678
+ if (typeVar->getImpl().isKeyPathType()) {
4679
+ return resolveKeyPath(typeVar, type, flags, locator)
4680
+ ? getTypeMatchSuccess()
4681
+ : getTypeMatchFailure(locator);
4682
+ }
4683
+
4678
4684
assignFixedType(typeVar, type, /*updateState=*/true,
4679
4685
/*notifyInference=*/!flags.contains(TMF_BindingTypeVariable));
4680
4686
@@ -12257,6 +12263,30 @@ bool ConstraintSystem::resolveTapBody(TypeVariableType *typeVar,
12257
12263
return !generateConstraints(tapExpr);
12258
12264
}
12259
12265
12266
+ bool ConstraintSystem::resolveKeyPath(TypeVariableType *typeVar,
12267
+ Type contextualType,
12268
+ TypeMatchOptions flags,
12269
+ ConstraintLocatorBuilder locator) {
12270
+ // Key path types recently gained Copyable, Escapable requirements.
12271
+ // The solver cannot account for that during inference because Root
12272
+ // and Value types are required to be only resolved enough to infer
12273
+ // a capability of a key path itself.
12274
+ if (auto *BGT = contextualType->getAs<BoundGenericType>()) {
12275
+ auto keyPathTy = openUnboundGenericType(
12276
+ BGT->getDecl(), BGT->getParent(), locator, /*isTypeResolution=*/false);
12277
+
12278
+ assignFixedType(
12279
+ typeVar, keyPathTy, /*updateState=*/true,
12280
+ /*notifyInference=*/!flags.contains(TMF_BindingTypeVariable));
12281
+ addConstraint(ConstraintKind::Equal, keyPathTy, contextualType, locator);
12282
+ return true;
12283
+ }
12284
+
12285
+ assignFixedType(typeVar, contextualType, /*updateState=*/true,
12286
+ /*notifyInference=*/!flags.contains(TMF_BindingTypeVariable));
12287
+ return true;
12288
+ }
12289
+
12260
12290
ConstraintSystem::SolutionKind
12261
12291
ConstraintSystem::simplifyDynamicTypeOfConstraint(
12262
12292
Type type1, Type type2,
0 commit comments