mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Since the "operation" inherits the context of the actor it should also be possible to reference its members without explicit use of `self.`.
52 lines
1.3 KiB
Swift
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`
|
|
}
|
|
}
|
|
}
|