mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Add the intermediate result for every leaf component
This commit is contained in:
@@ -2925,6 +2925,10 @@ internal func calculateAppendedKeyPathSize(
|
||||
|
||||
if isLast {
|
||||
break
|
||||
} else {
|
||||
// Add the intermediate type.
|
||||
result = MemoryLayout<Int>._roundingUpToAlignment(result)
|
||||
result &+= MemoryLayout<Int>.size
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1271,5 +1271,26 @@ if #available(SwiftStdlib 6.3, *) {
|
||||
}
|
||||
}
|
||||
|
||||
runAllTests()
|
||||
struct Thingy {
|
||||
var thingy: Thingy { self }
|
||||
|
||||
var a = 42
|
||||
}
|
||||
|
||||
extension Int {
|
||||
var subscripty: Thingy {
|
||||
Thingy(a: 67)
|
||||
}
|
||||
}
|
||||
|
||||
keyPath.test("appending keypath with multiple components") {
|
||||
var kp: KeyPath = \Thingy.self
|
||||
kp = kp.appending(path: \.thingy)
|
||||
kp = kp.appending(path: \.a.subscripty)
|
||||
|
||||
let t = Thingy()
|
||||
let value = t[keyPath: kp]
|
||||
expectEqual(value.a, 67)
|
||||
}
|
||||
|
||||
runAllTests()
|
||||
|
||||
Reference in New Issue
Block a user