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-2016] stride(from:0 as UInt8, though: 255, by: 2) should not trap. #44626
Comments
I think this would require an `x.advanced(by: Stride, limitedBy: Self) -> Self?` customization point in `Strideable`, and for the `stride(to:by: )` and `stride(through:by: )` iterators to use it. |
Not necessarily. It should be possible to check the distance to |
Hi @gonzalolarralde, so that you're aware, I've got a PR that's pending a bit of revision which addresses this bug: |
@xwu Thanks for the pointer! you saved me a ton of time 🙂 I was drafting a solution that looks similar in principle to yours to then try to figure out how to adapt it to make it fit the API stability story. |
Sure thing. I'll find some time to get the fix in my PR merged this week. I've been putting off updating the documentation comments but that can be done separately. |
perfect, thanks @xwu . TBH I got into this issue because I was hoping to be able to use enum E : Int, Strideable {
case one = 1, two, three, four
func distance(to other: Self) -> Int {
return other.rawValue - self.rawValue
}
func advanced(by n: Int) -> Self {
return Self(rawValue: self.rawValue + n)!
}
}
// current implementation requires this to past beyond `Test.four` to know it's finished.
print(Array(stride(from: Test.one, to: Test.four, by: 2))) so I attempted a naive fix that I wanted to verify how could be translated into something stable to the current implementation's inline methods. It is available here: gonzalolarralde@b846dba I opened SR-14325 to track the use-case I was hoping to enable, if you have any ideas/pointers on how a API-stable solution would look I would really appreciate your input! |
Fixed in PR#34860. |
Additional Detail from JIRA
md5: 568e368fa049264e9121cf3adc674d32
is duplicated by:
relates to:
Issue Description:
Right now it attempts to increment the current value beyond the bounds of
UInt8
, even though it is clear that the value will be greater than the stride's end.The text was updated successfully, but these errors were encountered: