File tree Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -438,7 +438,13 @@ - (BOOL)isEqual:(id)other {
438
438
// Legacy behavior: Don't proxy to Swift Hashable or Equatable
439
439
return NO ; // We know the ids are different
440
440
}
441
-
441
+ if (isObjCTaggedPointer (other)) {
442
+ // Swift class types cannot be tagged, and a Swift Equatable conformance
443
+ // cannot validly be called for an object of a different type, so this can
444
+ // only be incorrect if someone has an Equatable that's invalid in an
445
+ // extremely specific way (unsafeBitCasting `other` to an unrelated type)
446
+ return NO ;
447
+ }
442
448
443
449
// Get Swift type for self and other
444
450
auto selfMetadata = _swift_getClassOfAllocated (self);
Original file line number Diff line number Diff line change @@ -22,6 +22,10 @@ struct MyNonEquatableStruct {
22
22
var text : String
23
23
}
24
24
25
+ class MyEquatableClass : Equatable {
26
+ static func == ( lhs: MyEquatableClass , rhs: MyEquatableClass ) -> Bool { true }
27
+ }
28
+
25
29
BridgeEquatableToObjC . test ( " Bridge equatable struct " ) {
26
30
let swiftA = MyEquatableStruct ( text: " xABC " )
27
31
let swiftB = swiftA
@@ -46,5 +50,13 @@ BridgeEquatableToObjC.test("Bridge non-equatable struct") {
46
50
expectEqual ( objcResult, false )
47
51
}
48
52
53
+ BridgeEquatableToObjC . test ( " Compare tagged pointer to equatable SwiftObject " ) {
54
+ let literal = " The quick brown fox jumps over the lazy dog "
55
+ let bridgedLiteral = literal as NSString
56
+ let foo = MyEquatableClass ( )
57
+ let bridgedFoo = foo as AnyObject
58
+ let result = bridgedFoo. isEqual ( bridgedLiteral)
59
+ expectEqual ( result, false )
60
+ }
49
61
50
62
runAllTests ( )
You can’t perform that action at this time.
0 commit comments