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
Previously, we were ignoring the explicit `nonisolated`
attribute on an actor initializer. This only has a
noticable effect if the initializer is `async`: an actor
hop is being emitted even though isolation was explicitly
not requested.
While we internally treat the isolation of an unadorned
actor initializer as if it were `nonisolated`, if the
programmer explicitly requests it, then it should be honored
in an async init too. Thus, this patch tells definite initialization
to skip the insertion of the hop, instead treating a `nonisolated`
initializer as though it has the escaping-use restriction.
resolves rdar://84164173
Copy file name to clipboardExpand all lines: test/Concurrency/actor_definite_init.swift
+22-1Lines changed: 22 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -403,4 +403,25 @@ actor EscapeArtist {
403
403
404
404
func isolatedMethod(){ x +=1}
405
405
nonisolatedfunc nonisolated(){}
406
-
}
406
+
}
407
+
408
+
@available(SwiftStdlib 5.5,*)
409
+
actorAhmad{
410
+
func f(){}
411
+
412
+
nonisolatedinit(v1:Void){
413
+
Task.detached{awaitself.f()} // expected-warning {{actor 'self' cannot be captured by a closure from a non-isolated, designated initializer}}
414
+
// expected-note@-1 {{convenience initializers allow non-isolated use of 'self' once initialized}}
415
+
416
+
f() // expected-warning {{this use of actor 'self' cannot appear in a non-isolated, designated initializer}}
417
+
// expected-note@-1 {{convenience initializers allow non-isolated use of 'self' once initialized}}
418
+
}
419
+
420
+
nonisolatedinit(v2:Void)async{
421
+
Task.detached{awaitself.f()} // expected-warning {{actor 'self' cannot be captured by a closure from a non-isolated, designated initializer}} {{3-15=}}
422
+
// expected-note@-1 {{convenience initializers allow non-isolated use of 'self' once initialized}}
423
+
424
+
f() // expected-warning {{this use of actor 'self' cannot appear in a non-isolated, designated initializer}}
425
+
// expected-note@-1 {{convenience initializers allow non-isolated use of 'self' once initialized}}
0 commit comments