Since the release 1.0.1, sorting an identified array using a KeyPathComparator fails when it internally accesses the subscript. It was previously working on v1.0.0
Checklist
[X] If possible, I've reproduced the issue using the main branch of this package.
func testIdentifiedArraySort() {
struct Item: Identifiable {
let id: Int
}
var items: IdentifiedArrayOf<Item> = [Item(id: 3), Item(id: 2), Item(id: 1)]
items.sort(using: KeyPathComparator(\.id))
XCTAssertEqual([1, 2, 3], items.map(\.id))
}
Actual behavior
It crashes when it hits the precondition in the subscript (we removed an element, but its id can already be found elsewhere in the array we're working on).
Steps to reproduce
The following test should pass (and passes on v1.0.0):
func testIdentifiedArraySort() {
struct Item: Identifiable {
let id: Int
}
var items: IdentifiedArrayOf<Item> = [Item(id: 3), Item(id: 2), Item(id: 1)]
items.sort(using: KeyPathComparator(\.id))
XCTAssertEqual([1, 2, 3], items.map(\.id))
}
Note that sorting using the closure comparison works.
Identified Collections version information
1.0.1
Destination operating system
iOS 17
Xcode version information
Version 15.3 (15E5202a)
Swift Compiler version information
swift-driver version: 1.90.11.1 Apple Swift version 5.10 (swiftlang-5.10.0.13 clang-1500.3.9.4)
Target: arm64-apple-macosx14.0
Description
Since the release 1.0.1, sorting an identified array using a
KeyPathComparator
fails when it internally accesses the subscript. It was previously working on v1.0.0Checklist
main
branch of this package.Expected behavior
Actual behavior
It crashes when it hits the precondition in the subscript (we removed an element, but its id can already be found elsewhere in the array we're working on).
Steps to reproduce
The following test should pass (and passes on v1.0.0):
Note that sorting using the closure comparison works.
Identified Collections version information
1.0.1
Destination operating system
iOS 17
Xcode version information
Version 15.3 (15E5202a)
Swift Compiler version information