File tree Expand file tree Collapse file tree 2 files changed +40
-1
lines changed
Expand file tree Collapse file tree 2 files changed +40
-1
lines changed Original file line number Diff line number Diff line change @@ -5920,7 +5920,8 @@ ActorReferenceResult ActorReferenceResult::forReference(
59205920 declIsolation.isGlobalActor ()) {
59215921 auto *init = dyn_cast<ConstructorDecl>(fromDC);
59225922 auto *decl = declRef.getDecl ();
5923- if (init && init->isDesignatedInit () && isStoredProperty (decl)) {
5923+ if (init && init->isDesignatedInit () && isStoredProperty (decl) &&
5924+ (!actorInstance || actorInstance->isSelf ())) {
59245925 auto type =
59255926 fromDC->mapTypeIntoContext (declRef.getDecl ()->getInterfaceType ());
59265927 if (!isSendableType (fromDC->getParentModule (), type)) {
Original file line number Diff line number Diff line change @@ -1531,3 +1531,41 @@ class OverridesNonsiolatedInit: SuperWithNonisolatedInit {
15311531 super. x = 10
15321532 }
15331533}
1534+
1535+ // expected-note@+1 2 {{class 'NonSendable' does not conform to the 'Sendable' protocol}}
1536+ class NonSendable { }
1537+
1538+ actor ProtectNonSendable {
1539+ // expected-note@+1 {{property declared here}}
1540+ let ns = NonSendable ( )
1541+
1542+ init ( ) { }
1543+
1544+ @MainActor init ( fromMain: Void ) {
1545+ // expected-warning@+1 {{actor-isolated property 'ns' can not be referenced from the main actor; this is an error in Swift 6}}
1546+ _ = self . ns
1547+ }
1548+ }
1549+
1550+ @MainActor
1551+ class ReferenceActor {
1552+ let a : ProtectNonSendable
1553+
1554+ init ( ) async {
1555+ self . a = ProtectNonSendable ( )
1556+
1557+ // expected-warning@+1 {{non-sendable type 'NonSendable' in asynchronous access to actor-isolated property 'ns' cannot cross actor boundary}}
1558+ _ = a. ns
1559+ }
1560+ }
1561+
1562+ actor AnotherActor {
1563+ let a : ProtectNonSendable
1564+
1565+ init ( ) {
1566+ self . a = ProtectNonSendable ( )
1567+
1568+ // expected-warning@+1 {{non-sendable type 'NonSendable' in asynchronous access to actor-isolated property 'ns' cannot cross actor boundary}}
1569+ _ = a. ns
1570+ }
1571+ }
You can’t perform that action at this time.
0 commit comments