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

Bug in String Slice Indices or Generic Code Generator

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Medium
    • Resolution: Duplicate
    • Component/s: Compiler, Standard Library
    • Labels:
      None
    • Environment:

      Swift 3.0 2016-05-03 (a) snapshot on Xcode 7.3.1 on OS X 10.11.4

      Description

      I am not sure if it is a standard library bug or a generics code generation issue as it does not show up in non-generic version of the same code. Run this code with the latest Swift 3.0 snapshot to see the issue:

      func subSequenceIndexBug
          <C: Collection
          where
          C.Iterator.Element: Equatable,
          C.SubSequence: Collection,
          C.SubSequence.Index == C.Index,
          C.SubSequence.Iterator.Element == C.Iterator.Element>
          (_ c: C, _ e: C.Iterator.Element)
      {
          let junction = c.index(c.startIndex, offsetBy: numericCast(5)) // Arbitrary split point.   
          if let i = c.suffix(from: junction).index(of: e) {
              print("Searched for \"\(e)\" and found \"\(c[i])\". Result of testing them for equality is: \(e == c[i])")
          }
      }
      
      subSequenceIndexBug("ABCDEFGHIJKLMNOPQRSTUVWXYZ".characters, "Q")
      // Prints: "Searched for "Q" and found "L". Result of testing them for equality is: false"    
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              hooman Hooman Mehr
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: