Repository: Quick/Nimble (swift)

Issue:
Identity checking tests no longer compile on 13.7.0
- [x] I have read [CONTRIBUTING](https://github.com/Quick/Nimble/blob/main/CONTRIBUTING.md) and have done my best to follow them.

Seems the current 13.7.0 made our tests stop building, namely due to these changes:

```
-public func be(_ expected: AnyObject?) -> Matcher<AnyObject> {
+public func be<T: AnyObject>(_ expected: T?) -> Matcher<T> {
```

We have a test checking whether a delegate (of a protocol type) is identical to an expected object:

```swift
protocol OurDelegate: AnyObject { }
...
var delegate: (any OurDelegate)?
...
expect(delegate).to(be(someObject))
```

which is a valid scenario imho.

@younata would it be possible to revert?

Pull request description:
Fixes https://github.com/Quick/Nimble/issues/1182

Seems like... the simplest way is to just have an overload for these that specifically take in AnyObject, instead of a generic conforming to AnyObject?

Checklist - While not every PR needs it, new features should consider this list:

- [x] Does this have tests?
- [x] Does this have documentation?
- [ ] Does this break the public API (Requires major version bump)?
- [ ] Is this a new feature (Requires minor version bump)?

Patch:
diff --git a/Sources/Nimble/Matchers/BeIdenticalTo.swift b/Sources/Nimble/Matchers/BeIdenticalTo.swift
index 85e5b50c8..ef8878d9a 100644
--- a/Sources/Nimble/Matchers/BeIdenticalTo.swift
+++ b/Sources/Nimble/Matchers/BeIdenticalTo.swift
@@ -1,6 +1,16 @@
 /// A Nimble matcher that succeeds when the actual value is the same instance
 /// as the expected instance.
 public func beIdenticalTo<T: AnyObject>(_ expected: T?) -> Matcher<T> {
+    _beIdenticalTo(expected)
+}
+
+/// A Nimble matcher that succeeds when the actual value is the same instance
+/// as the expected instance.
+public func beIdenticalTo(_ expected: AnyObject?) -> Matcher<AnyObject> {
+    _beIdenticalTo(expected)
+}
+
+private func _beIdenticalTo<T: AnyObject>(_ expected: T?) -> Matcher<T> {
     return Matcher.define { actualExpression in
         let actual = try actualExpression.evaluate()
 
@@ -36,7 +46,15 @@ public func !== (lhs: AsyncExpectation<AnyObject>, rhs: AnyObject?) async {
 ///
 /// Alias for "beIdenticalTo".
 public func be<T: AnyObject>(_ expected: T?) -> Matcher<T> {
-    return beIdenticalTo(expected)
+    return _beIdenticalTo(expected)
+}
+
+/// A Nimble matcher that succeeds when the actual value is the same instance
+/// as the expected instance.
+///
+/// Alias for "beIdenticalTo".
+public func be(_ expected: AnyObject?) -> Matcher<AnyObject> {
+    return _beIdenticalTo(expected)
 }
 
 #if canImport(Darwin)


Test patch:
diff --git a/Tests/NimbleTests/Matchers/BeIdenticalToObjectTest.swift b/Tests/NimbleTests/Matchers/BeIdenticalToObjectTest.swift
index 0ba2316d0..4091d0119 100644
--- a/Tests/NimbleTests/Matchers/BeIdenticalToObjectTest.swift
+++ b/Tests/NimbleTests/Matchers/BeIdenticalToObjectTest.swift
@@ -12,10 +12,21 @@ final class BeIdenticalToObjectTest: XCTestCase {
 
     func testBeIdenticalToPositive() {
         expect(self.testObjectA).to(beIdenticalTo(testObjectA))
+    }
+
+    func testbeIdenticalToAsSubmatcher() {
         // check that the typing works out when used as a submatcher.
+        expect(self.testObjectA).to(map({ $0 }, be(testObjectA)))
         expect(self.testObjectA).to(map({ $0 }, beIdenticalTo(testObjectA)))
     }
 
+    func testBeIdenticalToAnyObjectProtocol() {
+        let object = AnObjectImplementation()
+
+        expect(object as AnObjectProtocol).to(be(object))
+        expect(object as AnObjectProtocol).to(beIdenticalTo(object))
+    }
+
     func testBeIdenticalToNegative() {
         expect(self.testObjectA).toNot(beIdenticalTo(testObjectB))
     }
@@ -54,5 +65,9 @@ final class BeIdenticalToObjectTest: XCTestCase {
         expect(self.testObjectA) === testObjectA
         expect(self.testObjectA) !== testObjectB
     }
+}
 
+private protocol AnObjectProtocol: AnyObject {}
+private final class AnObjectImplementation: AnObjectProtocol {
+    init() {}
 }