This is misleading, you can pattern match an enum just fine without relying on Equatable or Hashable conformance. I expect a very large portion of all user-defined enums to not rely on its Hashable conformance.
The if case and guard case syntax doesn't require Equatable, and usage of == could prompt a fixit to add Equatable conformance. I don't think this change would increase the number of pointless switches people write.
I don't think it's worthwhile to differentiate between public and non-public enums, IMO the inconsistency with Codable/CaseIterable would just make things more confusing.
I've explained in numerous occasions to people who are new to Swift. Most of the time they got the impression that enums are automatically equitable everywhere, ran into associated values and got confused.
I was under the impression that directly comparing enum cases was an intrinsic part of an enum. And that comparing two enum cases when the type is known to be an enum would still be fine after this proposal. Is that not the case here?
…and when you pattern-match a simple enum, you find out whether or not it is a certain case—ie. whether it is equal to another instance. Literally all you can do with an instance of a simple enum is store it, pass it to a function, or check if it’s the same as another one. That is my whole point.
I am not talking about how it is spelled in source code, nor how it is implemented behind the scenes. I am talking about the fact that a simple enum is a set of mutually-exclusive values, and the only thing that can possibly be done with such a type is to check if two of them are the same.
Even if you define a whole slew of methods on a simple enum, that let you add them or mutate them or whatever, when you get down to brass tacks you’re either going to ignore the value, or you’re going to test which case it equals. Everything else is stamp collecting.
…although, thinking about it again (and apologies for the triple-post), the code-size concern isn’t really active harm. And if a library publishes a simple enum, why *shouldn’t* clients be able to compare them or store them in a Set?
So perhaps Joe Groff is right, and it should only be resilient enums which are exempt from the implicit synthesis.
I think we should remove it, if not only for consistency. And add Hashable as a fixit in the code migrator on all previously implicitly-conforming types.
To me there doesn’t seem any good reason to keep this around. If you make your own type, you need to specify what capabilities it has. It’s not like writing : Hashable on an enum is conceptually harder than writing it on your own class definition.
I don't know if it's been mentioned, but could we solve the resilience problem by making such implicit conformances non-public, and therefore only usable within the module that declares the enum?
Moreover, Swift 6 has been avoiding source breaks that require widespread migration, even if they can be automated, unless the change is meant to enable concurrency safety. This change would require a lot of types to explicitly declare conformances they used to get for free, and it has nothing to do with concurrency safety, so it wouldn't fit within Swift 6's goals.
The good news on this front, however, is that the ~ProtocolName syntax introduced by some of the recent ownership proposals could probably be extended to provide an opt-out for implicit Hashable synthesis. That wouldn't flip the default the way this pitch would, but it would at least make it possible for maintainers who cared about this feature to control it in some way. Because this wouldn't change the default behavior, it wouldn't be source-breaking and could be introduced in any release, not just one with a language version mode like Swift 6.