Dangerous default implementation of `==` under `Strideable`

The behavior you're seeing doesn't have to do with conforming to Comparable.

Rather, it's Strideable that has a default implementation of == (and <), and the presence of any non-synthesized implementation (default or not) takes precedence over the synthesized one (or rather more accurately, disables synthesis). Strideable's default implementation of equivalence boils down to lhs.distance(to: rhs) == 0.

The presence of these defaults is documented in Strideable, and it's even put in a box marked "Important":

The Strideable protocol provides default implementations for the equal-to (==) and less-than (<) operators that depend on the Stride type’s implementations.

The issue has been discussed here before, and there's even a hokey workaround I've suggested in the past to get the default synthesized implementation back.

2 Likes