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 @@ -5901,7 +5901,8 @@ ActorReferenceResult ActorReferenceResult::forReference(
5901
5901
declIsolation.isGlobalActor ()) {
5902
5902
auto *init = dyn_cast<ConstructorDecl>(fromDC);
5903
5903
auto *decl = declRef.getDecl ();
5904
- if (init && init->isDesignatedInit () && isStoredProperty (decl)) {
5904
+ if (init && init->isDesignatedInit () && isStoredProperty (decl) &&
5905
+ (!actorInstance || actorInstance->isSelf ())) {
5905
5906
auto type =
5906
5907
fromDC->mapTypeIntoContext (declRef.getDecl ()->getInterfaceType ());
5907
5908
if (!isSendableType (fromDC->getParentModule (), type)) {
Original file line number Diff line number Diff line change @@ -1531,3 +1531,41 @@ class OverridesNonsiolatedInit: SuperWithNonisolatedInit {
1531
1531
super. x = 10
1532
1532
}
1533
1533
}
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