Skip to content

Conversation

@stephencelis
Copy link
Member

NSObjects are equatable by object identity by default, which can lead to diff returning a confusing string with no insertions/removals when all properties look the same, as brought up in this TCA discussion. This PR attempts to surface the object identity mismatch when everything else is the same.

extension ObjectIdentifier: CustomDumpStringConvertible {
public var customDumpDescription: String {
self.debugDescription
.replacingOccurrences(of: "0x0*", with: "0x", options: .regularExpression)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shortens ObjectIdentifier(0x00000000000deadbeef) to ObjectIdentifier(0xdeadbeef).

Comment on lines +314 to +315
let showObjectIdentifiers = lhsItem != rhsItem
&& isMirrorEqual(Array(lhsMirror.children), Array(rhsMirror.children))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll only diff/print object identifiers if all the exposed properties are equal. This should avoid noise in classes where are objects are equatable across identity.

_ transform: (inout Mirror.Child, Int) -> Void = { _, _ in }
) {
guard !lhsMirror.children.isEmpty || !rhsMirror.children.isEmpty
guard !isMirrorEqual(Array(lhsMirror.children), Array(rhsMirror.children))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if there's a more performant approach...

guard !isMirrorEqual(Array(lhsMirror.children), Array(rhsMirror.children))
else {
print(
"// Not equal but no difference detected:"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll now print a message when no difference is detected.

"""
// Not equal but no difference detected:
- NeverEqualUser(…)
+ NeverEqualUser(…)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could expand the properties here to aid a bit more in debugging...

@stephencelis stephencelis merged commit c393756 into main Oct 25, 2021
@stephencelis stephencelis deleted the show-object-identity branch October 25, 2021 14:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants