@@ -163,6 +163,42 @@ bb0:
163
163
return %2 : $@callee_owned (Int32, Int32) -> (Bool, @error Error)
164
164
}
165
165
166
+ // Check if we can handle a non-throwing closure which is passed to a thunk accepting a throwing closure.
167
+
168
+ sil @simple_nonthrowing_closure : $@convention(thin) (Int32) -> Bool
169
+
170
+ // CHECK-LABEL: sil shared @{{.*}}throwing_thunk{{.*}} : $@convention(thin) (Int32) -> (Bool, @error Error) {
171
+ // CHECK: = function_ref @simple_nonthrowing_closure
172
+ // CHECK-NEXT: thin_to_thick_function
173
+ // CHECK-NEXT: convert_function
174
+ // CHECK-NEXT: try_apply
175
+ // CHECK: return
176
+ // CHECK: throw
177
+ sil @throwing_thunk : $@convention(thin) (Int32, @owned @callee_owned (Int32) -> (Bool, @error Error)) -> (Bool, @error Error) {
178
+ bb0(%0 : $Int32, %1 : $@callee_owned (Int32) -> (Bool, @error Error)):
179
+ try_apply %1(%0) : $@callee_owned (Int32) -> (Bool, @error Error), normal bb1, error bb2
180
+
181
+ bb1(%5 : $Bool):
182
+ return %5 : $Bool
183
+
184
+ bb2(%7 : $Error):
185
+ throw %7 : $Error
186
+ }
187
+
188
+ // CHECK-LABEL: sil @return_throwing_thunk_closure
189
+ // CHECK: [[F:%[0-9]+]] = function_ref @{{.*}}throwing_thunk{{.*}} : $@convention(thin) (Int32) -> (Bool, @error Error)
190
+ // CHECK: [[T:%[0-9]+]] = thin_to_thick_function [[F]]
191
+ // CHECK: return [[T]]
192
+ sil @return_throwing_thunk_closure : $@convention(thin) () -> @owned @callee_owned (Int32) -> (Bool, @error Error) {
193
+ bb0:
194
+ %c1 = function_ref @simple_nonthrowing_closure : $@convention(thin) (Int32) -> Bool
195
+ %c2 = thin_to_thick_function %c1 : $@convention(thin) (Int32) -> Bool to $@callee_owned (Int32) -> Bool
196
+ %c3 = convert_function %c2 : $@callee_owned (Int32) -> Bool to $@callee_owned (Int32) -> (Bool, @error Error)
197
+ %t1 = function_ref @throwing_thunk : $@convention(thin) (Int32, @owned @callee_owned (Int32) -> (Bool, @error Error)) -> (Bool, @error Error)
198
+ %2 = partial_apply %t1(%c3) : $@convention(thin) (Int32, @owned @callee_owned (Int32) -> (Bool, @error Error)) -> (Bool, @error Error)
199
+ return %2 : $@callee_owned (Int32) -> (Bool, @error Error)
200
+ }
201
+
166
202
// Negative tests
167
203
168
204
sil @swapped_arguments : $@convention(method) (Int32, Int32, @thin Int32.Type) -> Bool {
0 commit comments