Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-13937] Needless precondition in Collection distance #56334

Open
dabrahams opened this issue Dec 6, 2020 · 1 comment
Open

[SR-13937] Needless precondition in Collection distance #56334

dabrahams opened this issue Dec 6, 2020 · 1 comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. standard library Area: Standard library umbrella

Comments

@dabrahams
Copy link
Collaborator

Previous ID SR-13937
Radar None
Original Reporter @dabrahams
Type Bug
Additional Detail from JIRA
Votes 0
Component/s Standard Library
Labels Bug
Assignee None
Priority Medium

md5: 79626c31d137f57975f0b894a587bfcd

Issue Description:

The precondition in Collection.distance that reads “Only BidirectionalCollections can have end come before start” fires even for {{BidirectionalCollection}} models unless the implementor of the collection is hyper-vigilant and implements their own distance method.

We could solve this problem by adding a default implementation of distance for BidirectionalCollections, but we're already doing a test/branch even on collections that are non-bidirectional, to detect the precondition violation. We might as well just do the right thing in all cases.

#34981 takes a first crack at an implementation.

@dabrahams
Copy link
Collaborator Author

Hm. We can't lift the precondition in documentation without causing existing working forward collections to be broken. However, we could in principle change the implementation so it works properly for bidirectional collections.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. standard library Area: Standard library umbrella
Projects
None yet
Development

No branches or pull requests

1 participant