Uploaded image for project: 'Swift'
  1. Swift
  2. SR-11588

Warn about derived Hashable implementation if there's a custom Equatable

    XMLWordPrintable

    Details

      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 a Hashable 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's Equatable conformance and see if it isImplicit(). If it is, emit a warning.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              jgiola Jacopo Andrea Giola
              Reporter:
              beccadax Becca Royal-Gordon
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Dates

                Created:
                Updated: