Merge pull request #80081 from xedin/rdar-143161190

[CSSimplify] Open key path type before assignment to its record requirements
This commit is contained in:
Pavel Yaskevich
2025-03-19 09:50:11 -07:00
committed by GitHub
8 changed files with 110 additions and 4 deletions

View File

@@ -4675,6 +4675,12 @@ ConstraintSystem::matchTypesBindTypeVar(
: getTypeMatchFailure(locator);
}
if (typeVar->getImpl().isKeyPathType()) {
return resolveKeyPath(typeVar, type, flags, locator)
? getTypeMatchSuccess()
: getTypeMatchFailure(locator);
}
assignFixedType(typeVar, type, /*updateState=*/true,
/*notifyInference=*/!flags.contains(TMF_BindingTypeVariable));
@@ -12257,6 +12263,30 @@ bool ConstraintSystem::resolveTapBody(TypeVariableType *typeVar,
return !generateConstraints(tapExpr);
}
bool ConstraintSystem::resolveKeyPath(TypeVariableType *typeVar,
Type contextualType,
TypeMatchOptions flags,
ConstraintLocatorBuilder locator) {
// Key path types recently gained Copyable, Escapable requirements.
// The solver cannot account for that during inference because Root
// and Value types are required to be only resolved enough to infer
// a capability of a key path itself.
if (auto *BGT = contextualType->getAs<BoundGenericType>()) {
auto keyPathTy = openUnboundGenericType(
BGT->getDecl(), BGT->getParent(), locator, /*isTypeResolution=*/false);
assignFixedType(
typeVar, keyPathTy, /*updateState=*/true,
/*notifyInference=*/!flags.contains(TMF_BindingTypeVariable));
addConstraint(ConstraintKind::Equal, keyPathTy, contextualType, locator);
return true;
}
assignFixedType(typeVar, contextualType, /*updateState=*/true,
/*notifyInference=*/!flags.contains(TMF_BindingTypeVariable));
return true;
}
ConstraintSystem::SolutionKind
ConstraintSystem::simplifyDynamicTypeOfConstraint(
Type type1, Type type2,