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

`DefaultIndices` conditional conformances incomplete

    XMLWordPrintable

    Details

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

      Description

      This program crashes with: Fatal error: Only BidirectionalCollections can have end come before start. It should not.

      extension Collection {
        func generic_distance(from i: Index, to j: Index) -> Int {
          distance(from: i, to: j)
        }
      }
      
      extension RandomAccessCollection {
        var isRandomAccess: Bool { true }
      }
      
      let r = (0...10).indices
      assert(r.isRandomAccess)
      print(r.distance(from: r.endIndex, to: r.startIndex))
      print(r.generic_distance(from: r.endIndex, to: r.startIndex)) // trap
      

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            dabrahams Dave Abrahams
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: