From 38e36784d0d40aaa8822011d504af2c71872657f Mon Sep 17 00:00:00 2001 From: Dario Rexin Date: Wed, 4 Dec 2024 13:57:48 -1000 Subject: [PATCH] [IRGen] Check if type is empty instead of void in CallEmission::emitToUnmappedExplosionWithDirectTypedError rdar://140573912 This caused assertions to fail when using other empty types, like `Never` as the result type on typed throwing functions. --- lib/IRGen/GenCall.cpp | 2 +- test/IRGen/typed_throws.swift | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/IRGen/GenCall.cpp b/lib/IRGen/GenCall.cpp index 7a3b664def6c6..3294ccc821307 100644 --- a/lib/IRGen/GenCall.cpp +++ b/lib/IRGen/GenCall.cpp @@ -4564,7 +4564,7 @@ void CallEmission::emitToUnmappedExplosionWithDirectTypedError( } // If the regular result type is void, there is nothing to explode - if (!resultType.isVoid()) { + if (!nativeSchema.empty()) { Explosion resultExplosion; if (auto *structTy = dyn_cast(nativeSchema.getExpandedType(IGF.IGM))) { diff --git a/test/IRGen/typed_throws.swift b/test/IRGen/typed_throws.swift index dff2c604c77f7..2951cf5a015c7 100644 --- a/test/IRGen/typed_throws.swift +++ b/test/IRGen/typed_throws.swift @@ -252,3 +252,16 @@ public func reabstractAsyncVoidThrowsNever() async { struct LoadableGeneric: Error {} func throwsLoadableGeneric(_: E) throws(LoadableGeneric) {} + +@inline(never) +func throwError() throws(SmallError) -> Never { + throw SmallError(x: 1) +} + +func conditionallyCallsThrowError(b: Bool) throws(SmallError) -> Int { + if b { + try throwError() + } else { + return 0 + } +}