[swift-users] Why can't Swift properly calculate this conformance?

Daryle Walker darylew at mac.com
Fri Dec 29 20:24:47 CST 2017


I ran into a problem while playing around with sequences that generate equally-partitioned sub-collections. (For example, have a collection of 15 elements; make it a collection of 5 elements instead, each a sub-collection of 3 original elements.) I recall the issue on StackOverflow at <https://stackoverflow.com/q/48016960/1010226> (“Cannot conform to RandomAccessCollection due to Stride type”).

I could easily make a Collection and upgrade it to a BidirectionalCollection, but when I did the obvious upgrade to RandomAccessCollection, I got an error that C.IndexDistance type doesn’t conform to SignedInteger, although the type should be Int! A fix is to use a where-clause to fix IndexDistance as Int in advance.

Why would that work? And, from glancing over a 1.5-month e-mail backlog, IndexDistance has been retired to be hard-coded as Int. But that just hides the problem; either IndexDistance was under-specified, or there’s something deficient in Swift’s reverse-engineering of associated types. I want to be sure the last scenario isn’t the case, so we wouldn’t run into similar issues in the future.

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT com 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20171229/dd2a2649/attachment.html>


More information about the swift-users mailing list