diff --git a/lib/IRGen/GenCall.cpp b/lib/IRGen/GenCall.cpp index 22f88968e0b3c..2d7f721f91ab8 100644 --- a/lib/IRGen/GenCall.cpp +++ b/lib/IRGen/GenCall.cpp @@ -3231,7 +3231,19 @@ class AsyncCallEmission final : public CallEmission { bool mayReturnErrorDirectly = mayReturnTypedErrorDirectly(); if (mayReturnErrorDirectly && !nativeSchema.requiresIndirect()) { - return emitToUnmappedExplosionWithDirectTypedError(resultType, result, + llvm::Value *resultAgg; + if (resultTys.size() == 1) { + resultAgg = Builder.CreateExtractValue(result, numAsyncContextParams); + } else { + auto resultTy = llvm::StructType::get(IGM.getLLVMContext(), resultTys); + resultAgg = llvm::UndefValue::get(resultTy); + for (unsigned i = 0, e = resultTys.size(); i != e; ++i) { + llvm::Value *elt = + Builder.CreateExtractValue(result, numAsyncContextParams + i); + resultAgg = Builder.CreateInsertValue(resultAgg, elt, i); + } + } + return emitToUnmappedExplosionWithDirectTypedError(resultType, resultAgg, out); } else if (resultTys.size() == 1) { result = Builder.CreateExtractValue(result, numAsyncContextParams); diff --git a/test/IRGen/typed_throws.swift b/test/IRGen/typed_throws.swift index 86b13a344e4e7..62e67c5234f43 100644 --- a/test/IRGen/typed_throws.swift +++ b/test/IRGen/typed_throws.swift @@ -188,3 +188,20 @@ func throwsGenericAsync(x: Bool, y: T) async throws(T) -> Int { return 32 } + +enum TinyError: Error { + case a +} + +@available(SwiftStdlib 6.0, *) +func mayThrowAsyncTiny(x: Bool) async throws(TinyError) -> Bool { + guard x else { + throw .a + } + return false +} + +@available(SwiftStdlib 6.0, *) +func callsMayThrowAsyncTiny(x: Bool) async { + _ = try! await mayThrowAsyncTiny(x: x) +}