Amendment to SE-0185: Synthesis of conformances declared on same-file extensions

The core team has approved an amendment to SE-0185 "Synthesizing Equatable and Hashable conformance to allow synthesis of conformances declared on same-file extensions. For example, the following is now well-formed, and will synthesize a conditional conformance of A to Equatable:

struct A<T> {
    var x: T
extension A: Equatable where T: Equatable {} // okay: synthesizes == in this extension

The synthesis is restricted to extensions within the same file as the primary type definition to ensure that all stored properties are guaranteed to be visible to the extension in which synthesis occurs. This change applies to synthesized conformances of Hashable, Equatable, Encodable, and Decodable.



Shouldn't this thread be in #evolution:announce instead?

Is this perhaps a little bit of a hack around the fundamental question here: should extensions in the same file behave as if they were written directly in the type declaration itself? This affects other things, like whether you should be able to declare stored properties in same-file extensions (somewhat difficult because of conditional extensions), and probably other limitations that I can't recall offhand. Maybe this is just a special case, and I can see the motivation in the example which can't be written directly on the type, but it would be nice to have a simple mental model here.

Edit: I'm not proposing this, or saying it's a great idea, but one example of another area this might impact would be if protocols could declare stored properties. Then these protocols could be restricted to being conformed to directly on the type or in a same-file extension.

Now that you're saying it, could this potentially close the door for stored properties in extensions altogether?

You're right, I should have posted it there. Thanks!

1 Like

I have moved this post to "Evolution > Announcements".

Hi Ted, you should delete the other thread then because there is a duplicate now.


1 Like