Skip to content

Commit 0598b8c

Browse files
committed
[stdlib] Task.immediate annotate operation parameter with @_implicitSelfCapture
Since the "operation" inherits the context of the actor it should also be possible to reference its members without explicit use of `self.`.
1 parent 8c05636 commit 0598b8c

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

stdlib/public/Concurrency/Task+immediate.swift.gyb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ extension Task where Failure == ${FAILURE_TYPE} {
3838
public static func startSynchronously(
3939
name: String? = nil,
4040
priority: TaskPriority? = nil,
41-
@_inheritActorContext(always) _ operation: sending @isolated(any) @escaping () async throws -> Success
41+
@_implicitSelfCapture @_inheritActorContext(always) _ operation: sending @isolated(any) @escaping () async throws -> Success
4242
) -> Task<Success, ${FAILURE_TYPE}> {
4343
immediate(name: name, priority: priority, operation: operation)
4444
}
@@ -73,7 +73,7 @@ extension Task where Failure == ${FAILURE_TYPE} {
7373
priority: TaskPriority? = nil,
7474
% # NOTE: This closure cannot be 'sending' because we'll trigger ' pattern that the region based isolation checker does not understand how to check'
7575
% # In this case: `func syncOnMyGlobalActor() { Task.immediate { @MyGlobalActor in } }`
76-
@_inheritActorContext(always) operation: sending @isolated(any) @escaping () async throws -> Success
76+
@_implicitSelfCapture @_inheritActorContext(always) operation: sending @isolated(any) @escaping () async throws -> Success
7777
) -> Task<Success, ${FAILURE_TYPE}> {
7878

7979
let builtinSerialExecutor =

test/Concurrency/startImmediatelyIsolation.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,14 @@ func async() async throws {
3838
group.addImmediateTaskUnlessCancelled { () async throws -> Void in }
3939
}
4040
}
41+
42+
@available(SwiftStdlib 6.2, *)
43+
actor TestSelfCapture {
44+
func method() {}
45+
46+
func test() {
47+
Task.immediate {
48+
method() // Ok due to `@_implicitSelfCapture`
49+
}
50+
}
51+
}

0 commit comments

Comments
 (0)