4

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:

  • 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?

4

1 回答 1

2

好消息

最新的开发者。2018 年 6 月 5 日的快照按预期工作:


坏消息

最新的 -release- 版本4.1.2不工作。

于 2018-06-06T13:35:22.250 回答