@@ -124,8 +124,7 @@ func TestEquatableHash(_ e: AnyObject)
124
124
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
125
125
// Legacy behavior: Equatable in Swift => ObjC hashes with identity
126
126
TestSwiftObjectNSObjectDefaultHashValue(e)
127
- let msg = " Obj- C `-hash` ... type `SwiftObjectNSObject.\(type(of: e) ) ` ... Equatable but not Hashable\n"
128
- fputs(msg, stderr)
127
+ fakeEquatableWarning(e)
129
128
#else
130
129
// New behavior: These should have a constant hash value
131
130
TestSwiftObjectNSObjectHashValue(e, 1)
@@ -143,11 +142,19 @@ func TestNonEquatableHash(_ e: AnyObject)
143
142
// CHECK-NEXT: d ##SwiftObjectNSObject.D##
144
143
// CHECK-NEXT: S ##{{.*}}SwiftObject##
145
144
146
- // Full message is longer, but this is the essential part ...
145
+ // Verify that the runtime emits the warning that we expected ...
147
146
// CHECK-NEXT: Obj-C `-hash` {{.*}} type `SwiftObjectNSObject.E` {{.*}} Equatable but not Hashable
148
147
// CHECK-NEXT: Obj-C `-hash` {{.*}} type `SwiftObjectNSObject.E1` {{.*}} Equatable but not Hashable
149
148
// CHECK-NEXT: Obj-C `-hash` {{.*}} type `SwiftObjectNSObject.E2` {{.*}} Equatable but not Hashable
150
149
150
+ // If we're checking legacy behavior or unsupported platform, then
151
+ // the warning above won't be emitted. This function emits a fake
152
+ // message that will satisfy the checks above in such cases.
153
+ func fakeEquatableWarning(e: AnyObject) {
154
+ let msg = " Obj- C `-hash` ... type `SwiftObjectNSObject.\(type(of: e) ) ` ... Equatable but not Hashable\n"
155
+ fputs(msg, stderr)
156
+ }
157
+
151
158
// Temporarily disable this test on older OSes until we have time to
152
159
// look into why it's failing there. rdar://problem/47870743
153
160
if #available(OSX 10.12, iOS 10.0, *) {
@@ -213,7 +220,7 @@ if #available(OSX 10.12, iOS 10.0, *) {
213
220
fputs( " c ##SwiftObjectNSObject. C##\n" , stderr)
214
221
fputs ( " d ##SwiftObjectNSObject.D## \n " , stderr)
215
222
fputs ( " S ##Swift._SwiftObject## \n " , stderr)
216
- fputs ( " Obj-C `-hash` ... type `SwiftObjectNSObject.E` ... Equatable but not Hashable " , stderr )
217
- fputs ( " Obj-C `-hash` ... type `SwiftObjectNSObject.E1` ... Equatable but not Hashable " , stderr )
218
- fputs ( " Obj-C `-hash` ... type `SwiftObjectNSObject.E2` ... Equatable but not Hashable " , stderr )
223
+ fakeEquatableWarning ( E ( i : 1 ) )
224
+ fakeEquatableWarning ( E1 ( i : 1 ) )
225
+ fakeEquatableWarning ( E2 ( i : 1 ) )
219
226
}
0 commit comments