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