Skip to content

Infer error conformance for type parameters used in typed throws #69181

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

Conversation

DougGregor
Copy link
Member

The type that occurs as the thrown error type must conform to the Error protocol. Infer this conformance when the type is a type parameter in the signature of a function.

This lets us write, e.g.,

extension Collection {
  func map<U, E>(body: (Element) throws(E) -> U) throws(E) -> [U] { ... }
}

without needing the E: Error bit.

The type that occurs as the thrown error type must conform to the
`Error` protocol. Infer this conformance when the type is a type
parameter in the signature of a function.
@DougGregor
Copy link
Member Author

@swift-ci please smoke test

@DougGregor DougGregor merged commit 38161f0 into swiftlang:main Oct 14, 2023
@DougGregor DougGregor deleted the infer-error-conformance-from-thrown-type branch October 14, 2023 03:50

// Inference of Error conformance from the use of a generic parameter in typed
// throws.
func requiresError<E: Error>(_: E.Type) { }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A -debug-generic-signatures | FileCheck test might be more direct than the requiresError() thing, but it probably doesn't matter

@DougGregor DougGregor mentioned this pull request Oct 16, 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.

2 participants