Foundation's range(of:options:) doesn't support Swift 4's Substring type

Originator:jp
Number:rdar://33838766 Date Originated:10-Aug-2017 04:33 PM
Status:Open Resolved:
Product:Developer Tools Product Version:Xcode 9 beta 5 (9M202q)
Classification:Serious Bug Reproducible:Always
 
Summary:
Foundation's range(of:options:) doesn't support Swift 4's Substring type. The range returned is calculated in the original string, not the substring.

Steps to Reproduce:
Run the following code on macOS (in a Playground or via the command line):

```swift
import Foundation

let str = "Yo Hello, playground"
let start = str.index(str.startIndex, offsetBy: 3)
let substr = str[start...]

if let commaSpaceEnd = substr.range(of: ", ", options: .backwards)?.upperBound {
    print(substr[commaSpaceEnd...])
}

if let commaSpaceEnd = str.range(of: ", ", options: .backwards)?.upperBound {
    print(str[commaSpaceEnd...])
}
```

Expected Results:
Should print:

playground
playground

Actual Results:
Actually prints:

o, playground
playground

Version:
Xcode 9 beta 5 (9M202q)

Notes:

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!