Skip to content

[4.2] [Type checker] Warn about overrides of NSObject.hashValue. #18411

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

Conversation

DougGregor
Copy link
Member

@DougGregor DougGregor commented Jul 31, 2018

Explanation: NSObject.hashValue is provided to satisfy the hashValue constraint of
the Hashable protocol. However, it is not the correct customization
point for interoperating with Objective-C, because Objective-C code
will call through the -hash method. Warn about overrides of
NSObject.hashValue; users should override NSObject.hash instead. This is meant as
staging in Swift 4.2, so that a future Swift release can make NSObject.hashValue public rather than open.
Scope: Warns about code that is overriding an API that is not meant to be overridden. Overriding
this method can cause strange runtime behavior when bridging, so we don't expect that it's too common.
Risk: Very low; it's an isolated new warning.
Testing: Compiler regression tests, including new tests.
Reviewer: @rudkx
SR / Radar: rdar://problem/42780635

NSObject.hashValue is provided to satisfy the hashValue constraint of
the Hashable protocol. However, it is not the correct customization
point for interoperating with Objective-C, because Objective-C code
will call through the -hash method. Warn about overrides of
NSObject.hashValue; users should override NSObject.hash instead.

Fixes rdar://problem/42780635.

(cherry picked from commit cc4c992)
@DougGregor
Copy link
Member Author

@swift-ci please test

@DougGregor DougGregor changed the title [Type checker] Warn about overrides of NSObject.hashValue. [4.2] [Type checker] Warn about overrides of NSObject.hashValue. Jul 31, 2018
@DougGregor
Copy link
Member Author

@swift-ci please test

2 similar comments
@DougGregor
Copy link
Member Author

@swift-ci please test

@DougGregor
Copy link
Member Author

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 6176442

@rudkx rudkx self-requested a review July 31, 2018 23:14
Copy link
Contributor

@rudkx rudkx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@DougGregor
Copy link
Member Author

@swift-ci please nominate

@DougGregor DougGregor merged commit 4efb97a into swiftlang:swift-4.2-branch Aug 1, 2018
@DougGregor DougGregor deleted the warn-override-nsobject-hashvalue-4.2 branch August 1, 2018 16:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants