[SR-9331] NSMutableSet uses identity check instead of equality upon adding Swift class #51801
Labels
bug
A deviation from expected or documented behavior. Also: expected but undesirable behavior.
runtime
The Swift Runtime
standard library
Area: Standard library umbrella
Environment
Checked with both
Apple Swift version 4.0.3 (swiftlang-900.0.74.1 clang-900.0.39.2)
Target: x86_64-apple-macosx10.9
and
Apple Swift version 4.2.1 (swiftlang-1000.11.42 clang-1000.11.45.1)
Target: x86_64-apple-darwin17.7.0
Additional Detail from JIRA
md5: ff3f6afba9d8cb7ef2090342fe90af70
Issue Description:
I have a Swift class below. When I insert its 2 equal instances into a Swift Set upon insertion Hashable protocol implementation is used as expected. However when I insert the same instances into NSMutableSet none of the implementations (Hashable or NSObjectProtocol methods) are used.
When I disassemble the code, as I see _SwiftObject_hash method is called. But it just returns object address, so identity is used for duplicate checking.
When I change the class type to a Swift struct or a class that inherits NSObject everything works as expected.
I'm not sure if this is expected behavior. But if it's that's really confusing. It caused a bug in my project and cost me one day of debugging, trying alternatives etc. After searching for a while I couldn't find any resource referencing this behavior, so here is a bug report.
Usage:
The text was updated successfully, but these errors were encountered: