For DefaultIndices, I believe this can be fixed by implementing those methods in the extension granting Collection conformance to DefaultIndices.
The problem occurs because at the point where DefaultIndices conforms to Collection, the only available implementation for distance(from:to:) is the single-ended default version from Collection itself. So that becomes the witness for DefaultIndices.distance.
By putting a concrete implementation in that extension, the compiler will choose that version instead of the default. All the concrete version does is forward to _elements, so the correct, dynamically-dispatched method will be called.
In Swift 3.1.1, the example given does not trap. It calls to the correct implementation of `distance(from:to🙂`, and correctly prints -11 as the output for both expressions.
The triplicate witnesses for these indexing operations make it tricky to perfectly forward them to another collection; but AFAICT Nevin's fix successfully resolves the (almost universal) case where all three variants share the same implementation.
Additional Detail from JIRA
md5: 963ca68213205a6037a30d43644edfef
Issue Description:
This program crashes with: Fatal error: Only BidirectionalCollections can have end come before start. It should not.
The text was updated successfully, but these errors were encountered: