Synthesizing methods, but for classes?

First, sorry if I should have posted this in an existing thread instead of making a new one. It seems that the topics related to this are either at least several years old or not completely related, so I couldn't find one particularly good place to ask this.

I'm looking for information for why we don't synthesize certain methods and protocol conformances for classes like we largely do for structs today. In the original proposal for Equatable/Hashable generation in structs, the following was to used to justify that the same couldn't be done for classes:

  • Subclassing makes it complicated
  • Even if it's final, superclasses would make the conditions unclear

This makes sense. But if we're dealing with a final class that has no superclass and no Obj-C bridging, is there any reason why we can't synthesize those conformances the exact same way we do for structs today? The proposal does make a point that in reference types memberwise equality may not necessarily imply that two instances are equal, but that is something that can also happen in structs and is fixed today by having the dev opt-out of the automatic conformance for the particular type where that would be an issue.

Are there other reasons that would make this not possible?

1 Like