Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regression when using sort(using: Comparator) #69

Closed
2 tasks done
tgrapperon opened this issue May 12, 2024 · 0 comments · Fixed by #70
Closed
2 tasks done

Regression when using sort(using: Comparator) #69

tgrapperon opened this issue May 12, 2024 · 0 comments · Fixed by #70
Labels
bug Something isn't working

Comments

@tgrapperon
Copy link
Contributor

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.0

Checklist

  • If possible, I've reproduced the issue using the main branch of this package.
  • This issue hasn't been addressed in an existing GitHub issue or discussion.

Expected behavior

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
@tgrapperon tgrapperon added the bug Something isn't working label May 12, 2024
stephencelis added a commit that referenced this issue May 13, 2024
PR #66 fixed one issue but introduced a regression. This PR changes the
subscript setter to do a `swap` when identity of elements match
something that already exists in the collection.

I've also stubbed out a fake property testing suite that can hopefully
be expanded with more operations soon.

Fixes #69.
stephencelis added a commit that referenced this issue May 17, 2024
* Fix subscript set operation

PR #66 fixed one issue but introduced a regression. This PR changes the
subscript setter to do a `swap` when identity of elements match
something that already exists in the collection.

I've also stubbed out a fake property testing suite that can hopefully
be expanded with more operations soon.

Fixes #69.

* wip

* wip

* wip

* wip
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant