Consider this:
let r = stride(from: 5, through: 1, by: -1)
print(r.contains(3)) // false
Pass it through an array and now it works:
let r = stride(from: 5, through: 1, by: -1).map { $0 }
print(r.contains(3)) // true
Going forward also works:
let r = stride(from: 1, through: 5, by: 1)
print(r.contains(3)) // true
Doesn't make any sense to me. Am I misunderstanding how the stride
function works?
Using the latest Xcode 13 with Swift 5.5.
Thanks!
3 Likes
lukasa
(Cory Benfield)
2
Yeah, this looks like a bug: StrideThrough
implements a custom override of _customContainsEquatableElement
that assumes that the start is always less than the end:
@inlinable
public func _customContainsEquatableElement(
_ element: Element
) -> Bool? {
if element < _start || _end < element {
return false
}
return nil
}
}
3 Likes
lukasa
(Cory Benfield)
3
Please file an issue on bugs.swift.org and post the number here.
lukasa
(Cory Benfield)
4
Incidentally, StrideTo
is affected by the same bug.
xwu
(Xiaodi Wu)
5
Oof. Yes, @seanmrich, please file a bug and link here. I think the following PR will fix it but regardless it’ll be good to have a bug to reference.
Looks like a fix was submitted same day. Great job @xwu!