Add the intermediate result for every leaf component

This commit is contained in:
Alejandro Alonso
2025-10-22 13:00:55 -07:00
parent d652100c3c
commit 714fd26830
2 changed files with 26 additions and 1 deletions

View File

@@ -2925,6 +2925,10 @@ internal func calculateAppendedKeyPathSize(
if isLast {
break
} else {
// Add the intermediate type.
result = MemoryLayout<Int>._roundingUpToAlignment(result)
result &+= MemoryLayout<Int>.size
}
}

View File

@@ -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()