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
andHashable
conformanceUsers must opt-in to automatic synthesis by declaring their type as
Equatable
orHashable
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:
Swift version 4.1-dev (LLVM 260a172ffb, Clang cd84be6c42, Swift 05b1b2be7c)
Swift version 4.2-dev (LLVM d30879863e, Clang 041fd44ebe, Swift b08fb12358)
Am I missing something?
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.