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 {
438438 // Legacy behavior: Don't proxy to Swift Hashable or Equatable
439439 return NO ; // We know the ids are different
440440 }
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+ }
442448
443449 // Get Swift type for self and other
444450 auto selfMetadata = _swift_getClassOfAllocated (self);
Original file line number Diff line number Diff line change @@ -22,6 +22,10 @@ struct MyNonEquatableStruct {
2222 var text : String
2323}
2424
25+ class MyEquatableClass : Equatable {
26+ static func == ( lhs: MyEquatableClass , rhs: MyEquatableClass ) -> Bool { true }
27+ }
28+
2529BridgeEquatableToObjC . test ( " Bridge equatable struct " ) {
2630 let swiftA = MyEquatableStruct ( text: " xABC " )
2731 let swiftB = swiftA
@@ -46,5 +50,13 @@ BridgeEquatableToObjC.test("Bridge non-equatable struct") {
4650 expectEqual ( objcResult, false )
4751}
4852
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+ }
4961
5062runAllTests ( )
You can’t perform that action at this time.
0 commit comments