Skip to content

Conversation

tshortli
Copy link
Contributor

@tshortli tshortli commented Aug 27, 2025

Diagnose the availability of the specific accessors that are referenced implicitly via a key path reference. This causes setter availability to be diagnosed when passing a key path to a function that takes a WritableKeyPath.

Resolves rdar://157232221.

Also resolves #72809.

@tshortli
Copy link
Contributor Author

@swift-ci please test

@tshortli
Copy link
Contributor Author

@swift-ci please test source compatibility

Diagnose the availability of the specific accessors that are referenced
implicitly via a key path reference. This causes setter availability to be
diagnosed when passing a key path to a function that takes a `WritableKeyPath`.

Resolves rdar://157232221.
@tshortli tshortli force-pushed the key-path-availability branch from 8d76643 to 2d5824e Compare August 27, 2025 14:58
@tshortli
Copy link
Contributor Author

The source compatibility failures appear to be due to existing issues.

@tshortli
Copy link
Contributor Author

@swift-ci please smoke test

@tshortli tshortli enabled auto-merge August 27, 2025 14:58
@tshortli tshortli merged commit 1e51d30 into swiftlang:main Aug 27, 2025
3 checks passed
@tshortli tshortli deleted the key-path-availability branch August 27, 2025 20:43
tshortli added a commit to tshortli/swift that referenced this pull request Sep 24, 2025
Fixes a regression from swiftlang#83931.

Resolves rdar://160816035.
tshortli added a commit to tshortli/swift that referenced this pull request Sep 25, 2025
…king.

Accessor availability diagnostics for key path expressions were first
introduced by swiftlang#83931. Those changes were
insufficient because sometimes key path expressions are generated in the AST
with more mutability than is needed by the context and so setter availability
could be diagnosed inappropriately. Key path expression binding was refined in
swiftlang#84491 to make this less likely to
occur. However, there are still some circumstances in which a mutable key path
is generated in the AST and then immediately coerced into an immutable key path
to satisfy the contextual type. This change infers the immutability of these key
path expressions by looking through surrounding conversion expressions.
tshortli added a commit to tshortli/swift that referenced this pull request Sep 25, 2025
…king.

Accessor availability diagnostics for key path expressions were first
introduced by swiftlang#83931. Those changes were
insufficient because sometimes key path expressions are generated in the AST
with more mutability than is needed by the context and so setter availability
could be diagnosed inappropriately. Key path expression binding was refined in
swiftlang#84491 to make this less likely to
occur. However, there are still some circumstances in which a mutable key path
is generated in the AST and then immediately coerced into an immutable key path
to satisfy the contextual type. This change infers the immutability of these key
path expressions by looking through surrounding conversion expressions.
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.

Key path formed to setter with unavailable key path is writable
1 participant