@@ -5885,6 +5885,23 @@ ActorReferenceResult ActorReferenceResult::forReference(
5885
5885
return forSameConcurrencyDomain (declIsolation);
5886
5886
}
5887
5887
5888
+ // Initializing a global actor isolated stored property with a value
5889
+ // effectively passes that value from the init context into the global
5890
+ // actor context. This is only okay to do if the property type is Sendable.
5891
+ if (declIsolation.isGlobalActor () && isStoredProperty (declRef.getDecl ())) {
5892
+ auto *init = dyn_cast<ConstructorDecl>(fromDC);
5893
+ if (init && init->isDesignatedInit ()) {
5894
+ auto type =
5895
+ fromDC->mapTypeIntoContext (declRef.getDecl ()->getInterfaceType ());
5896
+ if (!isSendableType (fromDC->getParentModule (), type)) {
5897
+ // Treat the decl isolation as 'preconcurrency' to downgrade violations
5898
+ // to warnings, because violating Sendable here is accepted by the
5899
+ // Swift 5.9 compiler.
5900
+ return forEntersActor (declIsolation, Flags::Preconcurrency);
5901
+ }
5902
+ }
5903
+ }
5904
+
5888
5905
// If there is an instance and it is checked by flow isolation, treat it
5889
5906
// as being in the same concurrency domain.
5890
5907
if (actorInstance &&
@@ -5903,13 +5920,8 @@ ActorReferenceResult ActorReferenceResult::forReference(
5903
5920
5904
5921
// If there is an instance that corresponds to 'self',
5905
5922
// we are in a constructor or destructor, and we have a stored property of
5906
- // global-actor-qualified type, pretend we are in the same concurrency
5907
- // domain.
5908
- // FIXME: This is an odd carve-out that probably shouldn't have been allowed.
5909
- // It should at the very least be diagnosed, and either subsumed by flow
5910
- // isolation or banned outright.
5911
- // FIXME: At the very least, we should consistently use
5912
- // isActorInitOrDeInitContext here, but it only wants to think about actors.
5923
+ // global-actor-qualified type, then we have problems if the stored property
5924
+ // type is non-Sendable. Note that if we get here, the type must be Sendable.
5913
5925
if (actorInstance && actorInstance->isSelf () &&
5914
5926
isNonInheritedStorage (declRef.getDecl (), fromDC) &&
5915
5927
declIsolation.isGlobalActor () &&
0 commit comments