Skip to content

Commit 17093b3

Browse files
committed
[CSSimplify] Delay binding generic argument type variables to any Sendable
Prevent generic arguments from being assigned `any Sendable` directly, that should only happen through inference. This is required because we allow `any Sendable` -> `Any` conversion in modes without strict concurrency enabled to maintain source compatibility and let the developers annotate existing APIs with `any Sendable` and other concurrency attributes.
1 parent 02b4bac commit 17093b3

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4311,6 +4311,20 @@ ConstraintSystem::matchTypesBindTypeVar(
43114311
type = type->getRValueType();
43124312
}
43134313

4314+
// Prevent generic arguments from being assigned `any Sendable`
4315+
// directly, that should only happen through inference. This is
4316+
// required because we allow `any Sendable` -> `Any` conversion
4317+
// in modes without strict concurrency enabled to maintain source
4318+
// compatibility and let the developers annotate existing APIs
4319+
// with `any Sendable` and other concurrency attributes.
4320+
if (typeVar->getImpl().getGenericParameter() &&
4321+
!flags.contains(TMF_BindingTypeVariable) &&
4322+
type->isMarkerExistential()) {
4323+
auto constraintTy = type->castTo<ExistentialType>()->getConstraintType();
4324+
if (constraintTy->getKnownProtocol() == KnownProtocolKind::Sendable)
4325+
return formUnsolvedResult();
4326+
}
4327+
43144328
// Attempt to fix situations where type variable can't be bound
43154329
// to a particular type e.g. `l-value` or `inout`.
43164330
auto fixReferenceMismatch = [&](TypeVariableType *typeVar,

0 commit comments

Comments
 (0)