Skip to content

[Typed throws] Implement conformance checking for typed throws #69087

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 3 commits into from
Oct 11, 2023

Conversation

DougGregor
Copy link
Member

Implement conformance checking for typed throws, including associated type inference, so one can capture the type that is thrown from a witness in a concrete type in an associated type, including any Error (for untyped throws) and Never (for non-throwing functions). For example:

protocol FailureAssociatedType {
  associatedtype Failure: Error

  func f() throws(Failure)
}

struct S1: FailureAssociatedType {
  func f() throws(MyError) { } // infers Failure == MyError
}

struct S2: FailureAssociatedType {
  func f() throws { } // infers Failure == any Error
}

struct S3: FailureAssociatedType {
  func f() { } // infers Failure == Never
}

@DougGregor
Copy link
Member Author

@swift-ci please smoke test

Lift the subtyping check for thrown error types out of the constraint
solver, so we can re-use it elsewhere.

There is a minor diagnostic change, from one that is actively
misleading (it shows a legitimate conversion that's wrong) to one that
is correct, which comes from us not treating "dropping throws" as a
legitimate way to handle equality of function types.
…rrors

When comparing a requirement that uses typed throws and uses an
associated type for the thrown error type against a potential witness,
infer the associated type from the thrown error of the
witness---whether explicitly specified, untyped throws (`any Error`),
or non-throwing (`Never`).
@DougGregor DougGregor force-pushed the typed-throws-conformances branch from 119a719 to 7d7c726 Compare October 10, 2023 04:21
@DougGregor
Copy link
Member Author

@swift-ci please smoke test

1 similar comment
@DougGregor
Copy link
Member Author

@swift-ci please smoke test

@DougGregor
Copy link
Member Author

@swift-ci please test Windows

1 similar comment
@DougGregor
Copy link
Member Author

@swift-ci please test Windows

@DougGregor DougGregor merged commit a14f280 into swiftlang:main Oct 11, 2023
@DougGregor DougGregor deleted the typed-throws-conformances branch October 11, 2023 04:16
@DougGregor DougGregor mentioned this pull request Oct 11, 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