Nimble: Associated values in enum makes the use of old Matcher API instead of Predicate.

Created on 23 Sep 2020  路  9Comments  路  Source: Quick/Nimble

  • [x] I have read CONTRIBUTING and have done my best to follow them.

What did you do?

enum MyEnum: Equatable {
    case firstCase
    case secondCase
    case thirdCase(value: Int)
}

expect(MyEnum.firstCase).to(equal(.secondCase)) // this is fine
expect(MyEnum.firstCase).to(equal(.thirdCase(value: 10))) // this is also fine
var optionalEnum: MyEnum?
optionalEnum = .firstCase
expect(optionalEnum).to(equal(.secondCase)) // this is fine
expect(optionalEnum).to(equal(.thirdCase(value: 10))) // this produces warning that we are using old API ('to(_:description:)' is deprecated: Use Predicate instead)

When expected value is of an optional type and matcher value uses enum with associated value the old API is used.

What did you expect to happen?

expect(optionalEnum).to(equal(.thirdCase(value: 10))) should create Predicate instead of a Matcher.

What actually happened instead?

Matcher was used resulting in deprecated warning.

Environment

List the software versions you're using:

  • Nimble: 9.0.0-rc.3
  • Xcode Version: 12.0
  • Swift Version: 5.3

Please also mention which package manager you used and its version. Delete the
other package managers in this list:

  • Cocoapods: 1.9.3

Project that demonstrates the issue

Example code above.

Most helpful comment

I Just created a patch for this issue, let's hope the maintainers will have a look at it ;)

All 9 comments

I'm really not sure why Swift 5.3 compiler pick this up only for such specific case 馃

let third = MyEnum.thridCase(value: 10)
expect(optionalEnum).to(equal(third))

This uses the expected to. So I think this might be a compiler issue (regarding type inference).

I think you are right. Even providing the type explicitly fixes the warning:

expect(optionalEnum).to(equal(MyEnum.thirdCase(value: 10)))

Seeing the same problem too!

I'm also seeing this issue.

I Just created a patch for this issue, let's hope the maintainers will have a look at it ;)

@ikesyo any updates on this issue? When can we expect a major version bump?

Getting something similar here in Xcode 12.3:

let actualCommentIds: [Comment] = // ...
expect(actualCommentIds).toEventually(equal([comment.id]))

Something to do with the automatic conformance of Array<Equatable> to Equatable?

I tested this on Xcode 12.5 and doesn't happen anymore. Looks like the overload resolution is fixed/improved in Swift 5.4. Closing.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

zachlucas picture zachlucas  路  5Comments

RonanMcH picture RonanMcH  路  7Comments

ikesyo picture ikesyo  路  4Comments

delebedev picture delebedev  路  4Comments

msaehn picture msaehn  路  5Comments