File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed
Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -7551,6 +7551,20 @@ ConstraintSystem::inferKeyPathLiteralCapability(KeyPathExpr *keyPath) {
75517551 if (!storage)
75527552 return fail ();
75537553
7554+ switch (getActorIsolation (storage)) {
7555+ case ActorIsolation::Unspecified:
7556+ case ActorIsolation::Nonisolated:
7557+ case ActorIsolation::NonisolatedUnsafe:
7558+ break ;
7559+
7560+ // A reference to an actor isolated state make key path non-Sendable.
7561+ case ActorIsolation::ActorInstance:
7562+ case ActorIsolation::GlobalActor:
7563+ case ActorIsolation::GlobalActorUnsafe:
7564+ isSendable = false ;
7565+ break ;
7566+ }
7567+
75547568 if (isReadOnlyKeyPathComponent (storage, component.getLoc ())) {
75557569 mutability = KeyPathMutability::ReadOnly;
75567570 continue ;
Original file line number Diff line number Diff line change @@ -138,3 +138,19 @@ do {
138138
139139 _ = Test ( obj: " Hello " ) . utf8. count // Ok
140140}
141+
142+ // Global actor isolated properties.
143+ do {
144+ @MainActor struct Isolated {
145+ var data : Int = 42
146+ subscript( v: Int ) -> Bool { false }
147+ }
148+
149+ let dataKP = \Isolated . data
150+ let subscriptKP = \Isolated . [ 42 ]
151+
152+ let _: KeyPath < Isolated , Int > & Sendable = dataKP
153+ // expected-warning@-1 {{type 'WritableKeyPath<Isolated, Int>' does not conform to the 'Sendable' protocol}}
154+ let _: KeyPath < Isolated , Bool > & Sendable = subscriptKP
155+ // expected-warning@-1 {{type 'KeyPath<Isolated, Bool>' does not conform to the 'Sendable' protocol}}
156+ }
You can’t perform that action at this time.
0 commit comments