Closed swift-ci closed 6 years ago
cc @milseman
@swift-ci create
The precondition fires when Collection's implementation of offsetBy-based index is invoked rather than BidirectionalCollection's. This might be directly, or indirectly invoked via a method like distance. The question is, why is something producing a negative offset in a context generic over Collection and not BidirectionalCollection?
And the answer is https://github.com/apple/swift-evolution/blob/master/proposals/0143-conditional-conformances.md#overloading-across-constrained-extensions
TL;DR: the least restricted overload is picked when in generic context to allow for more types. Not sure where in the snippet above said generic context happens, though.
Karoy tracked this down to a playground-specific issue, which was fixed in https://github.com/apple/swift-xcode-playground-support/pull/26.
You did say you managed to get this to reproduce in an app, so if you see this again outside of a playground and you're not calling index(_:offsetBy:)
yourself, please let us know!
Comment by Paul Ossenbruggen (JIRA)
Apologies, I could have sworn it failed in the project but I admit I was in a bit of a hurry. I attached the updated project and all the tests pass, so you are correct, a playground issue. Thanks for resolving this issue so quickly!
Attachment: Download
Environment
Xcode Beta 3 MacBook Air OS X High SierraAdditional Detail from JIRA
| | | |------------------|-----------------| |Votes | 0 | |Component/s | Xcode Playground Support | |Labels | Bug | |Assignee | None | |Priority | Medium | md5: d9ee1a3d8bd5234232986876e8fce714Issue Description:
When I create playground with the code below, I get the following error when running.
Fatal error: Only BidirectionalCollections can be advanced by a negative amount
It seems editing parts of the text out can cause the error to go away. I don't see how this code goes backward in the collection. I was able to make it happen when in an App as well as a playground.
If I pass the string in as a parameter to the function I also don't get the error.
PlaygroundPage.current.liveView = views[0] as! NSView