Skip to content

Commit 2ac9f70

Browse files
committed
[Concurrency] Extra runtime test for global task local
1 parent 95da1b5 commit 2ac9f70

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

test/Concurrency/Runtime/async_task_locals_basic.swift

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@
88
// REQUIRES: concurrency_runtime
99
// UNSUPPORTED: back_deployment_runtime
1010

11-
final class StringLike: Sendable, CustomStringConvertible {
11+
final class StringLike: Sendable, ExpressibleByStringLiteral, CustomStringConvertible {
1212
let value: String
1313
init(_ value: String) {
1414
self.value = value
1515
}
16+
init(stringLiteral value: StringLiteralType) {
17+
self.value = value
18+
}
1619

1720
var description: String { value }
1821
}
@@ -33,6 +36,9 @@ enum TL {
3336
static var clazz: ClassTaskLocal?
3437
}
3538

39+
@TaskLocal
40+
var globalTaskLocal: StringLike = StringLike("<not-set>")
41+
3642
@available(SwiftStdlib 5.1, *)
3743
final class ClassTaskLocal: Sendable {
3844
init() {
@@ -217,6 +223,13 @@ func inside_actor() async {
217223
await Worker().setAndRead()
218224
}
219225

226+
@available(SwiftStdlib 5.1, *)
227+
func global_task_local() async {
228+
await $globalTaskLocal.withValue("value-1") {
229+
await printTaskLocalAsync($globalTaskLocal) // CHECK-NEXT: TaskLocal<StringLike>(defaultValue: <not-set>) (value-1)
230+
}
231+
}
232+
220233
@available(SwiftStdlib 5.1, *)
221234
@main struct Main {
222235
static func main() async {
@@ -229,5 +242,6 @@ func inside_actor() async {
229242
await nested_3_onlyTopContributesAsync()
230243
await nested_3_onlyTopContributesMixed()
231244
await inside_actor()
245+
await global_task_local()
232246
}
233247
}

0 commit comments

Comments
 (0)