-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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
Fix solution application for keypath function subtype conversions #71737
Fix solution application for keypath function subtype conversions #71737
Conversation
In swiftlang#39612 we added subtyping for keypaths-as-functions, but during application the implementation naively coerced the keypath expression itself to the inferred supertype, resulting in erroneous results. This patch updates the solution application logic to build the keypath-function conversion expression based entirely on the 'natural' keypath type, only converting to the inferred supertype at the end via the usual coerceToType machinery for function conversions.
@swift-ci please test |
@swift-ci please test source compatibility |
@xedin would love your eyes here when you have a chance! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense to me!
struct Test { | ||
var codingStack: [CodingStackEntry] | ||
var codingPath: [any CodingKey] { codingStack.map(\.key) } | ||
// CHECK: keypath $KeyPath<CodingStackEntry, URICoderCodingKey>, (root $CodingStackEntry; stored_property #CodingStackEntry.key : $URICoderCodingKey) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add a test-case with optional promotion as well for completeness.
@swift-ci please build toolchain macOS platform |
@swift-ci please test macOS platform |
@swift-ci please test Linux platform |
All of the source compatibility failures are macro related, including penny-bot |
@xedin as in, there's an unrelated macro issue here? Or you suspect this patch is somehow interfering with macro logic? |
Macro issue is unrelated, I saw this happen in other PRs. |
@swift-ci please smoke test macOS platform |
In #39612 we added subtyping for keypath-function conversions. However the implementation naively coerced the keypath expression itself to the inferred supertype, resulting in erroneous results. This patch updates the solution application logic to build the keypath-function conversion expression based entirely on the 'natural' keypath type, only converting to the inferred supertype at the end via the usual coerceToType machinery for function conversions.
Resolves #71423