-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Open
Description
Description
The Swift compiler crashes with signal 11 during IR generation when an async function uses typed throws with a nested error type under any generic type.
Environment
- Swift version: 6.2.3 (swiftlang-6.2.3.3.21 clang-1700.6.3.2)
- Target: arm64-apple-macosx26.0
- Crash location:
swift::irgen::emitAsyncReturn
Minimal Reproduction (4 lines)
public enum Box<T> {
public enum Error: Swift.Error { case fail }
public static func go() async throws(Error) {} // CRASHES
}Full reproduction repository: https://github.com/coenttb/swift-issue-irgen-async-typed-throws-noncopyable
To Reproduce
echo 'public enum Box<T> { public enum Error: Swift.Error { case fail }; public static func go() async throws(Error) {} }' > /tmp/crash.swift
swiftc -parse-as-library -emit-ir /tmp/crash.swiftStack Trace
error: compile command failed due to signal 11 (use -v to see invocation)
Stack dump:
0. Program arguments: swift-frontend -frontend -emit-ir ...
1. Apple Swift version 6.2.3 (swiftlang-6.2.3.3.21 clang-1700.6.3.2)
2. Compiling with effective version 5.10
3. While evaluating request IRGenRequest(IR Generation for file "...")
4. While emitting IR SIL function "@$s6test103BoxO2goyyYaAC5ErrorOyx_GYKFZ".
for 'go()' (at /tmp/crash.swift:1:...)
...
4 swift-frontend swift::irgen::emitAsyncReturn(...) + 904
Conditions Required
All three conditions must be present:
- Generic type - any generic parameter (e.g.,
Box<T>) - Nested error type - error type defined inside the generic
- Async + typed throws -
async throws(NestedError)
Verified Test Results
| Test | Description | Result |
|---|---|---|
| Sync function | throws(Error) without async |
✅ Compiles |
| Untyped throws | async throws (not typed) |
✅ Compiles |
| Non-generic | Box without generic parameter |
✅ Compiles |
| Top-level error | throws(TopLevelError) |
✅ Compiles |
| Nested return only | Nested return type, top-level error | ✅ Compiles |
| Typealias workaround | typealias Error = HoistedError |
✅ Compiles |
| With ~Copyable | Box<T: ~Copyable> |
❌ Crashes |
| Minimal generic | Box<T> with nested error |
❌ Crashes |
Key finding: The crash is specifically triggered by nested error type in typed throws under any generic. ~Copyable is not required.
Workaround
Hoist error types to top-level and re-export via typealiases:
public enum BoxError: Swift.Error { case fail }
public enum Box<T> {
public typealias Error = BoxError
public static func go() async throws(Error) {} // Works
}Related Issues
- typed-
throwswith nested generic type crashes compiler #77297 - Typed throws with nested generic type crashes compiler - Async
initWith Typed Throw Crashes In Genericstruct,class, andactor#83011 - Async typed throws in generic context crashes compiler
Impact
This blocks adoption of typed throws in libraries using generics with nested error types and async APIs - a common pattern in I/O, networking, and resource management libraries.
Metadata
Metadata
Assignees
Labels
No labels