swiftswift4protocol-extension

'Equatable' cannot be automatically synthesized in an extension


This works:

// Conformance to protocol correctly synthesized by compiler 
struct MyStruct: Equatable { 
}

This doesn't:

struct MyStruct { 
}
// Doesn't work, even though the extension is in the same file
extension MyStruct: Equatable {
}

The error is very clear:

implementation of 'Equatable' cannot be automatically synthesized in an extension

My concern is that according to Swift's proposal SE-0185, this should be allowed:

SE-0185: Synthesizing Equatable and Hashable conformance

Users must opt-in to automatic synthesis by declaring their type as Equatable or Hashable without implementing any of their requirements. This conformance must be part of the original type declaration or in an extension in the same file (to ensure that private and fileprivate members can be accessed from the extension).

It says this was implemented in Swift 4.1 (apple/swift#9619).

However, when trying to compile, I get the error previously shown. I'm using Ubuntu 16.04, it fails with these two versions of swift I've got:

Am I missing something?


Solution

  • Good news

    The most recent dev. snapshot from June 5th, 2018 works as expected:


    Bad news

    Most recent -release- version 4.1.2 is not working.