@@ -201,3 +201,43 @@ func testSlowServerFromMain(slowServer: SlowServer) async throws {
201201 // CHECK: dealloc_stack [[RESUME_BUF]]
202202 let _: Int = await slowServer. doSomethingSlow ( " mail " )
203203}
204+
205+ // CHECK-LABEL: sil {{.*}}@${{.*}}26testThrowingMethodFromMain
206+ @MainActor
207+ func testThrowingMethodFromMain( slowServer: SlowServer ) async -> String {
208+ // CHECK: [[RESULT_BUF:%.*]] = alloc_stack $String
209+ // CHECK: [[STRING_ARG:%.*]] = apply {{%.*}}({{%.*}}) : $@convention(method) (@guaranteed String) -> @owned NSString
210+ // CHECK: [[METH:%.*]] = objc_method {{%.*}} : $SlowServer, #SlowServer.doSomethingDangerous!foreign
211+ // CHECK: [[RAW_CONT:%.*]] = get_async_continuation_addr [throws] String, [[RESULT_BUF]] : $*String
212+ // CHECK: [[CONT:%.*]] = struct $UnsafeContinuation<String, Error> ([[RAW_CONT]] : $Builtin.RawUnsafeContinuation)
213+ // CHECK: [[STORE_ALLOC:%.*]] = alloc_stack $@block_storage UnsafeContinuation<String, Error>
214+ // CHECK: [[PROJECTED:%.*]] = project_block_storage [[STORE_ALLOC]] : $*@block_storage
215+ // CHECK: store [[CONT]] to [trivial] [[PROJECTED]] : $*UnsafeContinuation<String, Error>
216+ // CHECK: [[INVOKER:%.*]] = function_ref @$sSo8NSStringCSgSo7NSErrorCSgIeyByy_SSTz_
217+ // CHECK: [[BLOCK:%.*]] = init_block_storage_header [[STORE_ALLOC]] {{.*}}, invoke [[INVOKER]]
218+ // CHECK: [[OPTIONAL_BLK:%.*]] = enum {{.*}}, #Optional.some!enumelt, [[BLOCK]]
219+ // CHECK: %28 = apply [[METH]]([[STRING_ARG]], [[OPTIONAL_BLK]], {{%.*}}) : $@convention(objc_method) (NSString, Optional<@convention(block) (Optional<NSString>, Optional<NSError>) -> ()>, SlowServer) -> ()
220+ // CHECK: [[STRING_ARG_COPY:%.*]] = copy_value [[STRING_ARG]] : $NSString
221+ // CHECK: dealloc_stack [[STORE_ALLOC]] : $*@block_storage UnsafeContinuation<String, Error>
222+ // CHECK: destroy_value [[STRING_ARG]] : $NSString
223+ // CHECK: await_async_continuation [[RAW_CONT]] : $Builtin.RawUnsafeContinuation, resume [[RESUME:bb[0-9]+]], error [[ERROR:bb[0-9]+]]
224+
225+ // CHECK: [[RESUME]]
226+ // CHECK: {{.*}} = load [take] [[RESULT_BUF]] : $*String
227+ // CHECK: hop_to_executor {{%.*}} : $MainActor
228+ // CHECK: fix_lifetime [[STRING_ARG_COPY]] : $NSString
229+ // CHECK: destroy_value [[STRING_ARG_COPY]] : $NSString
230+ // CHECK: dealloc_stack [[RESULT_BUF]] : $*String
231+
232+ // CHECK: [[ERROR]]
233+ // CHECK: hop_to_executor {{%.*}} : $MainActor
234+ // CHECK: fix_lifetime [[STRING_ARG_COPY]] : $NSString
235+ // CHECK: destroy_value [[STRING_ARG_COPY]] : $NSString
236+ // CHECK: dealloc_stack [[RESULT_BUF]] : $*String
237+
238+ do {
239+ return try await slowServer. doSomethingDangerous ( " run-with-scissors " )
240+ } catch {
241+ return " none "
242+ }
243+ }
0 commit comments