[Stdlib] Fix _swift_modifyAtWritableKeyPath_impl to check for ReferenceWritableKeyPaths.

Call through to _swift_modifyAtReferenceWritableKeyPath_impl in that case. This fixes an assertion failure (or worse) when upcasting a ReferenceWritableKeyPath and then using subscript(keyPath:) to modify a value with it.

rdar://74191390
This commit is contained in:
Mike Ash
2021-02-11 13:58:34 -05:00
parent 22acb2fc9f
commit a84a3a8f23
2 changed files with 15 additions and 0 deletions

View File

@@ -1041,6 +1041,16 @@ keyPath.test("ReferenceWritableKeyPath statically typed as WritableKeyPath") {
expectEqual(outer[keyPath: upcastKeyPath], 43)
outer[keyPath: upcastKeyPath] = 44
expectEqual(outer[keyPath: upcastKeyPath], 44)
func setWithInout<T>(_ lhs: inout T, _ rhs: T) { lhs = rhs }
expectEqual(outer[keyPath: keyPath], 44)
setWithInout(&outer[keyPath: keyPath], 45);
expectEqual(outer[keyPath: keyPath], 45)
expectEqual(outer[keyPath: upcastKeyPath], 45)
setWithInout(&outer[keyPath: upcastKeyPath], 46)
expectEqual(outer[keyPath: upcastKeyPath], 46)
}
runAllTests()