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

Fix -[RLMSwiftCollectionBase isEqual:] #7229

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

lukaskollmer
Copy link

@lukaskollmer lukaskollmer commented Apr 27, 2021

There is a bug in Realm where -[RLMSwiftCollectionBase isEqual:] does not correctly test for two List<>s equality.

Simple example:

class TestObject: RealmSwift.Object {
    let list = List<Int>()
}


let realm = try Realm()

let obj = TestObject()
obj.list.append(objectsIn: [1, 2, 3])

assert(obj.list == obj.list) // <- this will succeed (the list is currently still unmanaged)

try realm.write {
    realm.add(obj)
}

assert(obj.list == obj.list) // <- this will fail (because the list is now managed)

Why is this a problem? -[RLMSwiftCollectionBase isEqual:] is currently implemented in a way that it can only ever return YES for unmanaged list objects (see line 89).

This change was introduced by #6845, which attempted to add support for comparing unmanaged Lists and RLMArrays. However, it seems like this PR in fact changed the behaviour so that instead of also being able to compare unmanaged lists, you can now only compare unmanaged lists.

Note: The PR mentioned above also added -[RLMArray isEqual:], with a pretty much identical implementation (only return YES for unmanaged objects).
However, since RLMArray seems to be used exclusively for unmanaged arrays, I left that method unchanged. (RLMManagedArray seems to have a correct isEqual: implementation.)

it only ever compares the actual elements in the array if the objects are unmanaged
@lukaskollmer lukaskollmer changed the title Fix -[RLMListBase isEqual:]` Fix -[RLMListBase isEqual:] Apr 27, 2021
…kaskollmer/fix-list-equality

# Conflicts:
#	Realm/RLMSwiftCollectionBase.mm
@lukaskollmer lukaskollmer changed the title Fix -[RLMListBase isEqual:] Fix -[RLMSwiftCollectionBase isEqual:] Jul 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants