You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Because RandomAccessCollection has only semantic requirements that refine , it's easy for conditionally conforming types to implement the requirements in such a way that they don't receive dynamic dispatch, as seen in this forum post. We should add a note about implementing distance(from:to:) and index(_:offsetBy:) in the unconditional part of the type's declaration, if possible.
The text was updated successfully, but these errors were encountered:
The article on the blog that introduced conditional conformances contains an example type (LazySplitCollection) which is not a complete implementation of BidirectionalCollection.
Because of an additional conditional conformance it will trap in certain cases when traversed backwards, e.g. formIndex(_:offsetBy🙂 with a distance of -1, since BidirectionalCollection's default implementations can't be reached from Collection's default implementations. (/cc @airspeedswift.)
So indeed, this is not specific to RandomAccessCollection and we should consider extending the documentation to cover other (Collection) types as well. This could be done with a note or a label per member.
It might also be worth considering to extend this to the compiler as a warning or error as this behaviour is hard to catch without integration tests or benchmarks.
Additional Detail from JIRA
md5: da79f458aac27d0c55f972597f643c77
Issue Description:
Because
RandomAccessCollection
has only semantic requirements that refine , it's easy for conditionally conforming types to implement the requirements in such a way that they don't receive dynamic dispatch, as seen in this forum post. We should add a note about implementingdistance(from:to:)
andindex(_:offsetBy:)
in the unconditional part of the type's declaration, if possible.The text was updated successfully, but these errors were encountered: