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
[Concurrency] Implement a narrow carve out in the isolation
override checking for `NSObject.init()`
Overriding `NSObject.init()` within a `@MainActor`-isolated type
is difficult-to-impossible, especially if you need to call an initializer
from an intermediate superclass that is also `@MainActor`-isolated.
This won't admit a runtime data-race safety hole, because dynamic
isolation checks will be inserted in the @objc thunks under
`DynamicActorIsolation`, and direct calls will enforce `@MainActor`
as usual.
(cherry picked from commit 0d5e598)
Copy file name to clipboardExpand all lines: test/ClangImporter/objc_isolation_complete.swift
+14-2Lines changed: 14 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -32,15 +32,27 @@ class IsolatedSub: NXSender {
32
32
}
33
33
}
34
34
35
+
classNotSendable{}
36
+
37
+
@MainActor
38
+
classNSObjectInitOverride:NSObject{
39
+
varns:NotSendable
40
+
41
+
overrideinit(){
42
+
self.ns =NotSendable()
43
+
super.init()
44
+
}
45
+
}
46
+
47
+
35
48
@objc
36
49
@MainActor
37
50
classTest:NSObject{
38
-
staticvarshared:Test? // expected-note {{mutation of this static property is only permitted within the actor}}
51
+
staticvarshared:Test?
39
52
40
53
overrideinit(){
41
54
super.init()
42
55
43
56
Self.shared =self
44
-
// expected-warning@-1 {{main actor-isolated static property 'shared' can not be mutated from a nonisolated context; this is an error in the Swift 6 language mode}}
0 commit comments