Skip to content
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

NSObject conformance to Equatable is stealthy #72797

Open
igor-makarov opened this issue Apr 3, 2024 · 0 comments
Open

NSObject conformance to Equatable is stealthy #72797

igor-makarov opened this issue Apr 3, 2024 · 0 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels

Comments

@igor-makarov
Copy link

Description

NSObject has a conformance to Equatable which delegates to -[isEqual:].

On the face of it, this is not a bad idea: use Objective-C's conventions where applicable.

However, most classes do not override -[isEqual:] and use the default implementation, causing all sorts of unexpected bugs.

While it's impractical to warn users of default implementation pitfalls in each case, it might be useful to provide a diagnostic where this is possible. For example, #72765 is caused by such a default conformance.

Reproduction

class ClassA: NSObject, Equatable {} // error: Redundant conformance of 'ClassA' to protocol 'Equatable'
protocol SneakyProtocol: Equatable {}
class ClassB: NSObject, SneakyProtocol {} // no problem 

Expected behavior

Some kind of warning about the default conformance undermining the user's intent.

Environment

swift-driver version: 1.87.3 Apple Swift version 5.9.2 (swiftlang-5.9.2.2.56 clang-1500.1.0.2.5)
Target: arm64-apple-macosx14.0

Additional information

No response

@igor-makarov igor-makarov added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels labels Apr 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels
Projects
None yet
Development

No branches or pull requests

1 participant