Skip to content

Commit 461b293

Browse files
authored
Merge pull request #17467 from dmcyk/sr-7497
2 parents 04999aa + 3620ba3 commit 461b293

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

stdlib/public/core/KeyPath.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public class AnyKeyPath: Hashable, _AppendKeyPath {
5959
/// of this instance.
6060
@_effects(releasenone)
6161
final public func hash(into hasher: inout Hasher) {
62+
ObjectIdentifier(type(of: self)).hash(into: &hasher)
6263
return withBuffer {
6364
var buffer = $0
6465
while true {
@@ -597,7 +598,6 @@ internal enum KeyPathComponent: Hashable {
597598

598599
@_effects(releasenone)
599600
internal func hash(into hasher: inout Hasher) {
600-
var hasher = hasher
601601
func appendHashFromArgument(
602602
_ argument: KeyPathComponent.ArgumentRef?
603603
) {

test/stdlib/KeyPathImplementation.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,10 @@ keyPathImpl.test("equality") {
657657
}
658658

659659
expectNotEqual(s_c_z_p_x, s_c_z_p_y)
660+
expectNotEqual(s_c_z_p_x.hashValue, s_c_z_p_y.hashValue)
661+
660662
expectNotEqual(s_c_z_p_y, s_c_z_p_x)
663+
expectNotEqual(s_c_z_p_y.hashValue, s_c_z_p_x.hashValue)
661664

662665
// Different path type
663666
let s_c_z_p = ReferenceWritableKeyPath<S<S<String>>, Point>
@@ -677,6 +680,24 @@ keyPathImpl.test("equality") {
677680
expectNotEqual(s_c_z_p_x, s_c_z_p)
678681
expectNotEqual(s_c_z_p, s_c_z_p_x)
679682

683+
let s_x = WritableKeyPath<S<String>, Int>
684+
.build(capacityInBytes: MemoryLayout<Int>.size + 4) {
685+
$0.addHeader(trivial: true, hasReferencePrefix: false)
686+
$0.addStructComponent(offset: S<String>.x_offset)
687+
}
688+
689+
let si_x = WritableKeyPath<S<Int>, Int>
690+
.build(capacityInBytes: MemoryLayout<Int>.size + 4) {
691+
$0.addHeader(trivial: true, hasReferencePrefix: false)
692+
$0.addStructComponent(offset: S<Int>.x_offset)
693+
}
694+
695+
expectNotEqual(s_x, si_x)
696+
expectNotEqual(s_x.hashValue, si_x.hashValue)
697+
698+
expectNotEqual(si_x, s_x)
699+
expectNotEqual(si_x.hashValue, s_x.hashValue)
700+
680701
// Same path, no reference prefix
681702
let s_c_z_p_x_readonly = KeyPath<S<S<String>>, Double>
682703
.build(capacityInBytes: 7 * MemoryLayout<Int>.size + 4) {

0 commit comments

Comments
 (0)