Skip to content

⚠️[ObjectiveC] NSObject: Fix hashing implementation #18006

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

lorentey
Copy link
Member

@lorentey lorentey commented Jul 17, 2018

NSObject defines its own interface for hashing and equality. Subclasses must implement custom hashing by overriding the hash property, or NSSet and NSDictionary will not work correctly.

To prevent a common source of errors, make the hashValue property Swift-only, and non-overridable. (It was declared as @objc open by historical accident.)

Also add explicit, non-overridable definitions for hash(into:) and _rawHashValue(seed:) to prevent them from contributing to this issue in the future.

This is a potentially source-breaking change. Code that currently overrides NSObject.hashValue is almost certainly broken (because it violates the NSObject contract). However, this change trades a subtle runtime issue (that the code may or may not actually trigger) with an obvious compilation error.

rdar://problem/42623458

NSObject defines its own interface for hashing and equality. Subclasses must implement custom hashing by overriding the hash property, or NSSet and NSDictionary will not work correctly.

To prevent a common source of errors, make the hashValue property Swift-only, and non-overridable. (It was declared as @objc open by historical accident.)

This is a potentially source-breaking change.
@lorentey
Copy link
Member Author

@swift-ci please test

@lorentey
Copy link
Member Author

@swift-ci please test source compatibility

@lorentey lorentey changed the title [ObjectiveC] NSObject: Fix hashing implementation ⚠️[ObjectiveC] NSObject: Fix hashing implementation Jul 17, 2018
@lorentey lorentey requested a review from airspeedswift July 23, 2018 10:31
@lorentey
Copy link
Member Author

Updated and re-submitted as #20129

@lorentey lorentey closed this Oct 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant