Skip to content

Commit fc1da16

Browse files
committed
[Concurrency][TaskLocal] Add test for throwing out of a withLocal
1 parent 7dbccec commit fc1da16

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

stdlib/public/Concurrency/TaskLocal.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ extension Task {
102102
_taskLocalValuePush(task, keyType: Key.self, value: value)
103103
defer { _taskLocalValuePop(task) }
104104

105-
return try await body()
105+
return try await operation()
106106
}
107107

108108
}

test/Concurrency/Runtime/task_locals_basic.swift

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,20 @@ func simple_deinit() async {
7979
try! await printTaskLocal(\.clazz) // CHECK: ClazzKey: nil {{.*}}
8080
}
8181

82+
struct Boom: Error {
83+
let value: String
84+
}
85+
func simple_throw() async {
86+
do {
87+
try await Task.withLocal(\.clazz, boundTo: ClassTaskLocal()) {
88+
throw Boom(value: "oh no!")
89+
}
90+
} catch {
91+
//CHECK: error: Boom(value: "oh no!")
92+
print("error: \(error)")
93+
}
94+
}
95+
8296
func nested() async {
8397
try! await printTaskLocal(\.string) // CHECK: StringKey: <undefined> {{.*}}
8498
await Task.withLocal(\.string, boundTo: "hello") {
@@ -132,13 +146,13 @@ func withLocal_body_mustNotEscape() async {
132146
await Task.withLocal(\.string, boundTo: "xxx") {
133147
something = "very nice"
134148
}
135-
136149
}
137150

138151
@main struct Main {
139152
static func main() async {
140153
await simple()
141154
await simple_deinit()
155+
await simple_throw()
142156
await nested()
143157
await nested_allContribute()
144158
await nested_3_onlyTopContributes()

0 commit comments

Comments
 (0)