@@ -4675,6 +4675,12 @@ ConstraintSystem::matchTypesBindTypeVar(
46754675 : getTypeMatchFailure(locator);
46764676 }
46774677
4678+ if (typeVar->getImpl().isKeyPathType()) {
4679+ return resolveKeyPath(typeVar, type, flags, locator)
4680+ ? getTypeMatchSuccess()
4681+ : getTypeMatchFailure(locator);
4682+ }
4683+
46784684 assignFixedType(typeVar, type, /*updateState=*/true,
46794685 /*notifyInference=*/!flags.contains(TMF_BindingTypeVariable));
46804686
@@ -12257,6 +12263,30 @@ bool ConstraintSystem::resolveTapBody(TypeVariableType *typeVar,
1225712263 return !generateConstraints(tapExpr);
1225812264}
1225912265
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+
1226012290ConstraintSystem::SolutionKind
1226112291ConstraintSystem::simplifyDynamicTypeOfConstraint(
1226212292 Type type1, Type type2,
0 commit comments