Skip to content

Commit 31af4d9

Browse files
authored
Merge pull request #79243 from kubamracek/embedded-currenttask
[embedded] Add a test for withUnsafeCurrentTask
2 parents 716cc5c + 0d814ce commit 31af4d9

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend -enable-experimental-feature Embedded -parse-as-library %s -c -o %t/a.o
3+
// RUN: %target-clang %t/a.o -o %t/a.out -L%swift_obj_root/lib/swift/embedded/%target-cpu-apple-macos -lswift_Concurrency -lswift_ConcurrencyDefaultExecutor -dead_strip
4+
// RUN: %target-run %t/a.out | %FileCheck %s
5+
6+
// REQUIRES: executable_test
7+
// REQUIRES: swift_in_compiler
8+
// REQUIRES: optimized_stdlib
9+
// REQUIRES: OS=macosx
10+
// REQUIRES: swift_feature_Embedded
11+
12+
import _Concurrency
13+
14+
func printCurrentTaskNilOrNonNil() {
15+
withUnsafeCurrentTask { task in
16+
print(task == nil ? "nil" : "valid")
17+
}
18+
}
19+
20+
public func test() async -> Int {
21+
printCurrentTaskNilOrNonNil()
22+
return 42
23+
}
24+
25+
@main
26+
struct Main {
27+
static func main() async {
28+
print("main")
29+
// CHECK: main
30+
31+
printCurrentTaskNilOrNonNil()
32+
let t = Task {
33+
let x = await test()
34+
print(x == 42 ? "42" : "???")
35+
}
36+
await t.value
37+
// CHECK-NEXT: valid
38+
// CHECK-NEXT: valid
39+
// CHECK-NEXT: 42
40+
}
41+
}

0 commit comments

Comments
 (0)