Uploaded image for project: 'Swift'
  1. Swift
  2. SR-15384

StrideTo and StrideThrough `contains` methods don't handle decreasing ranges

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Medium
    • Resolution: Done
    • Component/s: Standard Library
    • Labels:
      None

      Description

      The `stride(from:to:by)` and `stride(from:through:by)` methods generate a `StrideTo` and `StrideThrough` struct respectively. When the end bound is less than the start bound, calling `contains(_` incorrectly reports false. Consider this:

      ```
      let r = stride(from: 5, through: 1, by: -1)
      print(r.contains(3)) // false
      ```

      Thanks to Cory Benfield, the issue was identified as an override of [`_customContainsEquatableElement`](https://forums.swift.org/t/is-there-a-bug-in-stride-fromby-or-is-it-me/53043).

        Attachments

          Activity

            People

            Assignee:
            xwu Xiaodi Wu
            Reporter:
            sean.rich Sean Rich
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: