-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[SR-11588] Warn about derived Hashable implementation if there's a custom Equatable #53993
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
Comments
Hi all, I want to take a chance on this issue but I have two question. 1. I don’t totally grasp the Sema logic and so there are some places where I can take inspiration on how I can get the type 2. There is already a possible text for the warning or I can come up with a proposal and change it then in the PR? |
Thanks for taking this on! To answer your questions: 1. You'll want to use 2. You'll need to add a new warning to DiagnosticsSema.def. Since you're the one implementing this feature, use diagnostics that make sense to you. 🙂 docs/Diagnostics.md has good guidelines for Swift's diagnostic style. (If you want to know what I'd do, I would probably diagnose the warning at the location of the user's A couple other things:
Good luck, and let me know if you need any help! |
One more thing to add: it's worth doing the other direction as well; types with a custom Hashable conformance should also have a custom Equatable. |
I’ve arrived to a solution to print the warning and the note, and I have a minimal test suite to check that in fact it is working. Can I open a PR in WIP to show the solution for confirmation and then for getting guidance in the future on missing test cases? Or is better to fill out all the cases and then open an official PR? |
@stephentyrone for the warning in the other direction is better to track it on a different issue/PR or I can expand the scope of this one? |
Please do open a draft PR and post the link here. (If you want to add the other warning too, you might as well use this bug report and PR to do it. No need to create more SRs and PRs to update.) |
I have opened #27801 but I discovered that is crashing on me when the type is an enum, and I’m trying to find why... |
Anyone knows who can help me on this PR? I’m unable to find how to check if the conformance is not in my module and so skip the witness search, or if I’m doing something wrong in the checks |
Hi brentdax (JIRA User), sorry to ping but I'm stuck on this and i don't know where I can find information on how to apply the correct check to avoid the crash described in the pull request. Do you know someone that can help me point in the right direction? Thank you |
Additional Detail from JIRA
md5: 023a941f08cf5b893763b728c33c0c83
relates to:
Issue Description:
Types that have a custom
==
almost surely also require a custom Hashable conformance (i.e. the synthesized one will be wrong). Ideally, we wouldn’t synthesize if there’s a custom equatable, but that’s not source-stable. The compiler should emit a warning if it synthesizes aHashable
conformance for a type whose==(Self, Self) -> Bool
implementation is not also synthesized.This should be relatively simple to do: in the "full Hashable derivation" part of DerivedConformanceEquatableHashable.cpp, after we have decided that we are definitely going to derive an implementation, find the
==
operator in the type'sEquatable
conformance and see if itisImplicit()
. If it is, emit a warning.The text was updated successfully, but these errors were encountered: