Files
swift-mirror/test/Concurrency/startImmediatelyIsolation.swift
Pavel Yaskevich 0598b8c9f4 [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.`.
2025-05-19 18:01:23 -07:00

52 lines
1.3 KiB
Swift

// RUN: %target-build-swift -swift-version 6 %s -strict-concurrency=complete -Xfrontend -verify
// REQUIRES: concurrency
@available(SwiftStdlib 6.2, *)
func sync() -> Task<String, Never> {
Task.immediate {
return ""
}
}
@available(SwiftStdlib 6.2, *)
func async() async throws {
let t1 = Task.immediate {
return ""
}
let _: String = await t1.value
let t2: Task<String, Error> = Task.immediate {
throw CancellationError()
}
let _: String = try await t2.value
await withTaskGroup(of: Int.self) { group in
group.addImmediateTask { 1 }
group.addImmediateTaskUnlessCancelled { 2 }
}
await withThrowingTaskGroup(of: Int.self) { group in
group.addImmediateTask { () async throws -> Int in 1 }
group.addImmediateTaskUnlessCancelled { () async throws -> Int in 2 }
}
await withDiscardingTaskGroup { group in
group.addImmediateTask { }
group.addImmediateTaskUnlessCancelled { }
}
try await withThrowingDiscardingTaskGroup { group in
group.addImmediateTask { () async throws -> Void in }
group.addImmediateTaskUnlessCancelled { () async throws -> Void in }
}
}
@available(SwiftStdlib 6.2, *)
actor TestSelfCapture {
func method() {}
func test() {
Task.immediate {
method() // Ok due to `@_implicitSelfCapture`
}
}
}