Skip to content

Commit d727495

Browse files
committed
[CSSolver] Handle situations when key path expression has an existential type
A way to mark key path as Sendable is to extend its type with `& Sendable`. This is something that makes the type of a key path expression an existential with superclass bound expressed as a known key path type.
1 parent 316e8f9 commit d727495

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

lib/Sema/CSApply.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5009,6 +5009,12 @@ namespace {
50095009
baseTy = fnTy->getParams()[0].getParameterType();
50105010
leafTy = fnTy->getResult();
50115011
isFunctionType = true;
5012+
} else if (auto *existential = exprType->getAs<ExistentialType>()) {
5013+
auto constrainedTy = existential->getConstraintType();
5014+
auto layout = constrainedTy->getExistentialLayout();
5015+
auto keyPathTy = layout.explicitSuperclass->castTo<BoundGenericType>();
5016+
baseTy = keyPathTy->getGenericArgs()[0];
5017+
leafTy = keyPathTy->getGenericArgs()[1];
50125018
} else {
50135019
auto keyPathTy = exprType->castTo<BoundGenericType>();
50145020
baseTy = keyPathTy->getGenericArgs()[0];

lib/Sema/CSSimplify.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12195,6 +12195,12 @@ ConstraintSystem::simplifyKeyPathConstraint(
1219512195
if (contextualTy->isPlaceholder())
1219612196
return true;
1219712197

12198+
// Situations like `any KeyPath<...> & Sendable`.
12199+
if (contextualTy->isExistentialType()) {
12200+
contextualTy = contextualTy->getExistentialLayout().explicitSuperclass;
12201+
assert(contextualTy);
12202+
}
12203+
1219812204
// If there are no other options the solver might end up picking
1219912205
// `AnyKeyPath` or `PartialKeyPath` based on a contextual conversion.
1220012206
// This is an error during normal type-checking but okay in

0 commit comments

Comments
 (0)