I have a protocol, ViewEdgeConvertible, that’s used to convert between directional and fixed view edges using a UITraitCollection:
public protocol ViewEdgeConvertible {
func fixedViewEdge(
using traitCollection: UITraitCollection?
) -> FixedViewEdge
func directionalViewEdge(
using traitCollection: UITraitCollection?
) -> DirectionalViewEdge
}
public enum FixedViewEdge: Equatable {
case top
case left
case right
case bottom
}
public enum DirectionalViewEdge: Equatable {
case top
case leading
case trailing
case bottom
}
Using this, I can convert freely between the two types given a trait collection, which lets me account for right-to-left layouts. But when I try to make an == implementation:
I get this warning: All paths through this function will call itself.
It looks like the compiler sees the == method between the two FixedViewEdge instances and defaults to this method I’ve implemented. Is there a way to write this that takes advantage of the synthesized Equatable conformance on the FixedViewEdge enum?
You probably also want to do that on DirectionalViewEdge so that directionalViewEdge1 == directionalViewEdge2 use the more performant Equatable implementation. (or maybe it'll get constant-folded anyway).
Personally, I'm not sure it's advisable to implement == over heterogeneous types.
That's very spooky, that a free function == and a static function ViewEdgeConvertible.== have different priorities (one below synthesized == and one above).