mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[CSApply] Optional chaining forces key path component to be r-value
Key path components with optional chaining unlike other places don't propagate l-value through optionals. Resolves: rdar://123638701
This commit is contained in:
@@ -652,3 +652,23 @@ struct Test {
|
||||
var codingPath: [any CodingKey] { codingStack.map(\.key) }
|
||||
// CHECK: keypath $KeyPath<CodingStackEntry, URICoderCodingKey>, (root $CodingStackEntry; stored_property #CodingStackEntry.key : $URICoderCodingKey)
|
||||
}
|
||||
|
||||
// rdar://123638701 - Make sure that optional chaining forces loads.
|
||||
func test_optional_chaining_with_function_conversion() {
|
||||
class Storage {}
|
||||
|
||||
class Elements {
|
||||
var db: Storage = Storage()
|
||||
}
|
||||
|
||||
class Source {
|
||||
var elements: Elements? = nil
|
||||
}
|
||||
|
||||
func test(data: [Source]) {
|
||||
// CHECK: {{.*}} = keypath $KeyPath<Source, Optional<Storage>>
|
||||
_ = data.compactMap(\.elements?.db)
|
||||
// CHECK: {{.*}} = keypath $KeyPath<Source, Storage>
|
||||
_ = data.compactMap(\.elements!.db)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user