Skip to content

Conversation

slavapestov
Copy link
Contributor

@slavapestov slavapestov commented Sep 10, 2025

When storing a closure with type () throws(any Error) -> () as a fully opaque value, we want to leave it unchanged, instead of re-abstracting it to throw the error indirectly. Thus, we had a special carveout here.

However, the carveout was too broad, because if the thrown error type contained type parameters, the resulting AbstractionPattern was invalid.

While fixing this I realized this entire hack is unsound in some cases, if you view the same value as a () throws(U) -> () vs an () -> throws(any Error) -> ().

Perhaps we should always box the thrown error when maximally abstracting a closure, but that would also be an ABI break.

When storing a closure with type `() throws(any Error) -> ()` as
a fully opaque error, we want to leave it unchanged, instead of
re-abstracting it to throw the error indirectly. Thus, we had
a special carveout here.

However, the carveout was too broad, because if the thrown error
type contained type parameters, the resulting AbstractionPattern
was invalid.

While fixing this I realized this entire hack is unsound in some
cases, if you view the same value as a `() throws(U) -> ()` vs
an `() -> throws(any Error) -> ()`.

Perhaps we should always box the thrown error when maximally
abstracting a closure, but that would also be an ABI break.

- Fixes swiftlang#84051
@slavapestov
Copy link
Contributor Author

@swift-ci Please smoke test

@slavapestov slavapestov merged commit 8362997 into swiftlang:main Sep 11, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Closure with typed throw crashes
1 participant