swiftlang / swift-experimental-string-processing

An early experimental general-purpose pattern matching engine for Swift.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Crash in `BidirectionalCollection.firstRange(of:)`

bjhomer opened this issue · comments

Description
BidirectionalCollection.firstRange(of:) crashes when the last element of the needle matches the last element of the haystack, but other elements do not match.

Steps to reproduce

let array = [1, 2, 3]
array.firstRange(of: [1, 3]) // Crash: index out of bounds

let str = "abc"
str.firstRange(of: "zc") // Crash: index out of bounds

Expected behavior
The above examples should not crash, but should instead return nil

Environment

$ swiftc -version
swift-driver version: 1.62.15 Apple Swift version 5.7.2 (swiftlang-5.7.2.135.5 clang-1400.0.29.51)
Target: arm64-apple-macosx13.0

Also seems to happen in Swift 5.8 (in the Xcode beta)

swiftc -version
$ swift-driver version: 1.75.1 Apple Swift version 5.8 (swiftlang-5.8.0.117.11 clang-1403.0.22.8.60)
Target: arm64-apple-macosx13.0

I believe that this is fixed in 5.8 and main with #631. Note that this is a runtime fix, so testing with the Xcode beta on a version of macOS with the 5.7 runtime is expected not to work.

@natecook1000 Could you transfer this issue to the string processing repo?

Given that it’s already fixed, are we cloning it just to close immediately, or is there a further problem to address?

or is there a further problem to address?

No, just seeing to it that issues end up in the right repos, even if they happen to be fixed by the time they do. It’s fine to close prior to transferring.

Steve's right, this was addressed by #631. Thanks!