Fix solution application for keypath function subtype conversions

In #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.
This commit is contained in:
Freddy Kellison-Linn
2024-02-19 15:09:08 -08:00
parent d35dcc8f9c
commit 2b2f780a21
2 changed files with 33 additions and 7 deletions

View File

@@ -637,3 +637,18 @@ struct TestKeyPathWithSomeType : DefineSomeType {
}
}
// apple/swift#71423
protocol CodingKey {}
struct URICoderCodingKey : CodingKey {}
struct CodingStackEntry {
var key: URICoderCodingKey
}
struct Test {
var codingStack: [CodingStackEntry]
var codingPath: [any CodingKey] { codingStack.map(\.key) }
// CHECK: keypath $KeyPath<CodingStackEntry, URICoderCodingKey>, (root $CodingStackEntry; stored_property #CodingStackEntry.key : $URICoderCodingKey)
}