@@ -67,7 +67,7 @@ struct CustomRawRepresentable: RawRepresentable, Hashable {
67
67
}
68
68
}
69
69
70
- suite. test ( " Custom hashing " ) {
70
+ suite. test ( " _rawHashValue forwarding " ) {
71
71
// In 5.0, RawRepresentable had a bogus default implementation for
72
72
// _rawHashValue(seed:) that interfered with custom hashing for
73
73
// RawRepresentable types. Adding a custom hash(into:) implementation should
@@ -81,4 +81,36 @@ suite.test("Custom hashing") {
81
81
}
82
82
}
83
83
84
+ struct Bogus : Hashable {
85
+ var hashValue : Int { 42 }
86
+ static func == ( left: Self , right: Self ) -> Bool { true }
87
+ }
88
+
89
+ struct CustomRawRepresentable2 : RawRepresentable , Hashable {
90
+ var rawValue : Bogus
91
+
92
+ init ? ( rawValue: Bogus ) {
93
+ self . rawValue = rawValue
94
+ }
95
+
96
+ func hash( into hasher: inout Hasher ) {
97
+ hasher. combine ( 23 )
98
+ }
99
+ }
100
+
101
+
102
+ suite. test ( " hashValue forwarding " ) {
103
+ // In versions up to and including 5.5, RawRepresentable had a bogus default
104
+ // implementation for `hashValue` that forwarded directly to
105
+ // `rawValue.hashValue`, instead of `self.hash(into:)`. Adding a custom
106
+ // hash(into:) implementation should always be enough to customize hashing.
107
+ //
108
+ // See https://github.com/apple/swift/pull/39155
109
+
110
+ if #available( macOS 9999 , iOS 9999 , tvOS 9999 , watchOS 9999 , * ) {
111
+ let r = CustomRawRepresentable2 ( rawValue: Bogus ( ) ) !
112
+ expectEqual ( r. hashValue, 23 . hashValue)
113
+ }
114
+ }
115
+
84
116
runAllTests ( )
0 commit comments