Skip to content

[6.2] Add lifetime dependencies on function types representing ~Escapable enum elements with ~Escapable payloads #82431

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 5 commits into from
Jun 24, 2025

Conversation

meg-gupta
Copy link
Contributor

@meg-gupta meg-gupta commented Jun 23, 2025

Explanation: Enum elements are represented as a function type. Enums can satisfy a protocol's static method constraint by defining a enum element with the same signature.

We do not infer lifetime dependence on function types related to EnumElementDecl. This results to source compatibility bugs in some cases since Optional is now conditionally ~Escapable. In the example below a protocol specifying a static some method ends up with a generated witness that does not have lifetime dependencies leading to illegible diagnostics.

public protocol OptionalType<Wrapped> {
    associatedtype Wrapped
    static func some(_ wrapped: Wrapped) -> Self
}

extension Optional: OptionalType {}

This PR adds lifetime dependencies for function types representative of EnumElementDecls.

Scope: Affects ~Escapable and conditionally ~Escapable types

Risk: Medium. New code is exercised in the type checker on all conditionally ~Escapable enums.

Main PR: #82354

Reviewer: @atrick

Testing: CI testing.

Issue: rdar://152104558

@meg-gupta
Copy link
Contributor Author

@swift-ci test

@meg-gupta meg-gupta marked this pull request as ready for review June 24, 2025 17:33
@meg-gupta meg-gupta requested a review from a team as a code owner June 24, 2025 17:33
@meg-gupta meg-gupta requested a review from tbkka June 24, 2025 17:33
@meg-gupta meg-gupta merged commit 1d1f9b0 into swiftlang:release/6.2 Jun 24, 2025
5 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.

2 participants