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: don't test for runtimeType equality for object comparison take 2 #192

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

Conversation

devmil
Copy link
Contributor

@devmil devmil commented Nov 22, 2024

Status

READY

Breaking Changes

NO

Description

Continuation of #188
As discussed in the referenced PR here an extended PR that adds a couple of tests to make sure that Equatable comparison still works as intended (e.g. different classes with same property values should be different) as well as adding a very far-fetched test-case that simulates non-Equatable classes with custom equality logic.

Related PRs

List related PRs against other branches:

branch PR
master link

Todos

  • Tests
  • Documentation
  • Examples

Steps to Test or Reproduce

Have an Equatable class with a field that's type is using a custom equality logic

class CustomEqualityVariant1;
class CustomEqualityVariant2;

final val1 = CustomEqualityVariant1();
final val2 = CustomEqualityVariant2();
val1 == val2

final equatableInstance1 = EquatableClass(val1);
final equatableInstance2 = EquatableClass(val2);

instance1 != instance2 // this was not the case pre 2.0.6

Impact to Remaining Code Base

This PR will affect:

  • !behavior change! will increase the set of equal==true combinations compared to 2.0.7 and 2.0.5 (all props that have a different runtimeType but are equal are now treated as equal)
  • restores 2.0.5 behavior for Equatable props of type List with different SubClass variants that are equal without sharing the same runtimeType

@devmil devmil force-pushed the fix/num_comparison_take2 branch from d0ac6c4 to 5e1a53c Compare November 24, 2024 12:22
Copy link
Owner

@felangel felangel left a comment

Choose a reason for hiding this comment

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

I took a closer look at v2.0.5 and this was not a breaking change from what I can see (runtimeType was still considered in the equality check). The new test you added fails in v2.0.5 so I don't think we should change this behavior now.

@devmil
Copy link
Contributor Author

devmil commented Nov 27, 2024

I took a closer look at v2.0.5 and this was not a breaking change from what I can see (runtimeType was still considered in the equality check). The new test you added fails in v2.0.5 so I don't think we should change this behavior now.

@felangel
True. Then I will take a deeper look on why equatable 2.0.6 (and 2.0.7 as well) breaks our code base and create a new PR.

But don't you think that the behavior expressed in the new unit tests is wrong? Regardless of being introduced in 2.0.6 or not?

@devmil
Copy link
Contributor Author

devmil commented Nov 28, 2024

@felangel
I digged deeper and found out why 2.0.6/2.0.7 breaks our code.
The piece of code is not using the custom equality objects directly but they are in a list.
2.0.5 branched out to the DeepCollectionEquality which internally doesn't do runtimeType checks (because it doesn't need to)

if (!_equality.equals(unit1, unit2)) return false;

2.0.6 replaced that approach with a custom list equality logic that uses the equatable equals logic (that has the runtimeType condition) for each item.
if (!objectsEquals(a.elementAt(i), b.elementAt(i))) return false;

I added a test that works in this branch as well as on 2.0.5 but fails on 2.0.6/2.0.7 to showcase the scenario

@devmil devmil requested a review from felangel November 28, 2024 11:14
@felangel
Copy link
Owner

felangel commented Jan 2, 2025

@felangel I digged deeper and found out why 2.0.6/2.0.7 breaks our code. The piece of code is not using the custom equality objects directly but they are in a list. 2.0.5 branched out to the DeepCollectionEquality which internally doesn't do runtimeType checks (because it doesn't need to)

if (!_equality.equals(unit1, unit2)) return false;

2.0.6 replaced that approach with a custom list equality logic that uses the equatable equals logic (that has the runtimeType condition) for each item.

if (!objectsEquals(a.elementAt(i), b.elementAt(i))) return false;

I added a test that works in this branch as well as on 2.0.5 but fails on 2.0.6/2.0.7 to showcase the scenario

Sorry for the delay (I was off for a lot of the holidays). Will try to get this merged later today or tomorrow 👍

@devmil
Copy link
Contributor Author

devmil commented Jan 2, 2025

Sorry for the delay (I was off for a lot of the holidays). Will try to get this merged later today or tomorrow 👍

No problem. We have a workaround by now.
I think it makes sense to do a major jump if you decide to take the changes in this PR as the behavior is different.

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.

2 participants