[swift-evolution] [Review] SE-0131: Add AnyHashable to the standard library

Pyry Jahkola pyry.jahkola at iki.fi
Tue Jul 26 00:25:41 CDT 2016


Dmitri Gribenko wrote:

>> There's one very obscure gotcha with AnyHashable that subclass instances of
>> a Hashable base class should be cast to the base type before wrapping into
>> AnyHashable, otherwise such wrapped values may break the equivalence law of
>> symmetry (`a == b` iff `b == a`).
> 
> The implementation that I have does not suffer from this issue.  (The
> initializer of AnyHashable walks the superclass chain and upcasts the
> value to the correct type.)

Brilliant! Glad that you found a resolution!

— Pyry


More information about the swift-evolution mailing list