You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: test/Concurrency/nonisolated_inherits_isolation.swift
+19Lines changed: 19 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -16,6 +16,11 @@
16
16
17
17
classNonSendableKlass{}
18
18
19
+
nonisolatedclassNonIsolatedNonSendableKlass{
20
+
func unspecifiedMethod()async{}
21
+
nonisolatedfunc nonisolatedMethod()async{}
22
+
}
23
+
19
24
func unspecifiedSyncUse<T>(_ t:T){}
20
25
func unspecifiedAsyncUse<T>(_ t:T)async{}
21
26
nonisolatedfunc nonisolatedSyncUse<T>(_ t:T){}
@@ -148,3 +153,17 @@ class MainActorKlass {
148
153
// expected-enabled-note @-1 {{sending main actor-isolated 'x4' to global actor 'CustomActor'-isolated global function 'sendToCustom' risks causing data races between global actor 'CustomActor'-isolated and main actor-isolated uses}}
149
154
}
150
155
}
156
+
157
+
// We should not error on either of these since c is in the main actor's region
158
+
// and our nonisolated/unspecified methods are inheriting the main actor
159
+
// isolation which is safe since they are type checked as something that cannot
160
+
// access any state that is outside of the current actor that c is reachable from.
await c.unspecifiedMethod() // expected-disabled-error {{sending 'c' risks causing data races}}
166
+
// expected-disabled-note @-1 {{sending main actor-isolated 'c' to nonisolated instance method 'unspecifiedMethod()' risks causing data races between nonisolated and main actor-isolated uses}}
167
+
await c.nonisolatedMethod() // expected-disabled-error {{sending 'c' risks causing data races}}
168
+
// expected-disabled-note @-1 {{sending main actor-isolated 'c' to nonisolated instance method 'nonisolatedMethod()' risks causing data races between nonisolated and main actor-isolated uses}}
0 commit comments