Skip to content

[Typed throws] Compute and use the caught error type of a do..catch block #68976

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 5, 2023

Conversation

DougGregor
Copy link
Member

The type that is caught by the catch clauses in a do..catch block is determined by the union of the thrown error types in the do statement. Compute this type and use it for the catch clauses. This does several things at once:

  • Makes the type of the implicit error be a more-specific concrete type when all throwing sites throw that same type
  • When there's a concrete type for the error, one can use patterns like .cancelled
  • Check that this error type can be rethrown in the current context
  • Verify that SIL generation involving do..catch with typed errors doesn't require any existentials.

…lock.

The type that is caught by the `catch` clauses in a `do..catch` block is
determined by the union of the thrown error types in the `do`
statement. Compute this type and use it for the catch clauses. This
does several things at once:

* Makes the type of the implicit `error` be a more-specific concrete
type when all throwing sites throw that same type
* When there's a concrete type for the error, one can use patterns
like `.cancelled`
* Check that this error type can be rethrown in the current context
* Verify that SIL generation involving do..catch with typed errors
doesn't require any existentials.
@DougGregor
Copy link
Member Author

@swift-ci please smoke test

@DougGregor DougGregor merged commit 698cfb9 into swiftlang:main Oct 5, 2023
@DougGregor DougGregor deleted the typed-do-catch branch October 5, 2023 12:06
@DougGregor DougGregor mentioned this pull request Oct 5, 2023
21 tasks
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.

1 participant