pointfreeco / swift-case-paths

🧰 Case paths extends the key path hierarchy to enum cases.
https://www.pointfree.co/collections/enums-and-structs/case-paths
MIT License
921 stars 108 forks source link

Failed to extract enum with AnyHashable associated value #83

Closed AmbarSeptian closed 1 year ago

AmbarSeptian commented 2 years ago

Describe the bug Hello guys, I have a project using CasePaths with version 0.1.3 and updating it with a huge leap into 0.8.1. After the update enum with the associated value of AnyHashable will fail to extract. The pattern in enum looks like this:

enum ParentAction {
    case loadPage
    case childrenAction(id: AnyHashable, action: ChildrenAction)
}

To Reproduce We can reproduce this by running tests in CasePathTests and changing the associated value from String to AnyHashable in this test

  func testPathExtractFromOptionalRoot() {
    enum Authentication {
      case authenticated(token: AnyHashable) // change from String to AnyHashable
      case unauthenticated
    }

    let root: Authentication? = .authenticated(token: "deadbeef")
    let path: CasePath<Authentication?, String> = /Authentication.authenticated
    for _ in 1...2 {
      let actual = path.extract(from: root)
      XCTAssertEqual(actual, "deadbeef")  // XCTAssertEqual failed: ("nil") is not equal to ("Optional("deadbeef")")
    }
  }

Expected behavior The extracted result should be not nil in the latest version and on (version 0.1.3), The tests above succeed both for the associated value String and AnyHashable

Environment