[swift-evolution] Pitch: Automatically deriving Equatable/Hashable for more value types

Nevin Brackett-Rozinsky nevin.brackettrozinsky at gmail.com
Fri May 5 10:15:56 CDT 2017


On Fri, May 5, 2017 at 1:47 AM, Xiaodi Wu via swift-evolution <
swift-evolution at swift.org> wrote:

> On Fri, May 5, 2017 at 12:41 AM, Brent Royal-Gordon <
> brent at architechies.com> wrote:
>
>> I would think only final classes could participate in this, since a
>> subclassable class would need to allow subclasses to override equality, and
>> you can't override a static `==` operator method.
>>
>
> I work so rarely with classes that I'm embarrassed to have to ask this
> question: can classes not satisfy Equatable with a `public class func ==`?
>

Currently:

class C: Equatable {
    class func == (lhs: C, rhs: C) -> Bool {
        return lhs === rhs
    }
}

Yields an error, “Operator '==' declared in non-final class 'C' must be
'final'”.

Nevin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170505/80f7f352/attachment.html>


More information about the swift-evolution mailing list