Skip to content

Conversation

@devalgupta404
Copy link

@devalgupta404 devalgupta404 commented Oct 18, 2025

This PR fixes the equality comparison for EqualUnmodifiableListView, EqualUnmodifiableSetView, and EqualUnmodifiableMapView to use content-based comparison instead of object reference comparison.

Changes

  • Updated == operator to use DeepCollectionEquality().equals() for content comparison
  • Updated hashCode to use DeepCollectionEquality().hash() for consistent hashing
  • Applied fixes to all three collection wrapper classes

Fixes

Resolves #1308

Impact

This fix ensures consistency between freezed List equality and freezed objects containing lists, which resolves the Riverpod ref.watch(Provider).select() issue mentioned in the GitHub issue.

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced equality comparison for collection-based objects. Collections are now compared using deep equality instead of reference equality, ensuring objects with identical collection contents are correctly recognized as equal. Hash code calculations updated accordingly.

@coderabbitai
Copy link

coderabbitai bot commented Oct 18, 2025

Walkthrough

The changes update equality and hash code implementations for EqualUnmodifiableListView, EqualUnmodifiableSetView, and EqualUnmodifiableMapView to use DeepCollectionEquality for comparing underlying collections, ensuring equality is based on content rather than object reference.

Changes

Cohort / File(s) Summary
Deep collection equality fix
packages/freezed_annotation/lib/freezed_annotation.dart
Updated == operator in three unmodifiable view classes to use DeepCollectionEquality().equals() instead of direct _source reference comparison; updated corresponding hashCode implementations to use DeepCollectionEquality().hash().

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

The changes follow a consistent pattern across three related classes with straightforward logic updates. Each modification replaces reference-based equality with deep content-based equality, making the intent clear and review effort minimal.

Poem

🐰 Deep within collections we hippity-hop,
No more comparing where references plop!
With equality checking what truly belongs,
Content sings out in DeepCollectionEquality's songs. 🥕✨

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The PR title clearly and accurately describes the main change: updating equality comparison for EqualUnmodifiableListView to use content-based comparison via DeepCollectionEquality. While the raw_summary indicates that the fix applies to three collection wrapper classes (ListView, SetView, and MapView), it is standard practice to mention the most prominent class in a PR title when multiple related classes receive the same fix. The title is sufficiently specific and conveys the primary objective of the changeset.
Linked Issues Check ✅ Passed The PR directly addresses all requirements from issue #1308. The code changes update equality and hashCode implementations for all three affected classes (EqualUnmodifiableListView, EqualUnmodifiableSetView, and EqualUnmodifiableMapView) to use DeepCollectionEquality for content-based comparison instead of reference-based comparison. This aligns with the stated objectives to fix the inconsistency between freezed List equality and equality for freezed Objects containing Lists, and ensures hashCode consistency with the new equality semantics.
Out of Scope Changes Check ✅ Passed All changes in the PR are directly related to the scope of linked issue #1308. Modifications are limited to the three collection wrapper classes and their equality and hashCode implementations, with no unrelated refactoring, no exported public signature changes, and no tangential modifications. The changes are precisely targeted at fixing the identified equality comparison bug.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7c9baf6 and 9d5f7dc.

📒 Files selected for processing (1)
  • packages/freezed_annotation/lib/freezed_annotation.dart (3 hunks)
🔇 Additional comments (4)
packages/freezed_annotation/lib/freezed_annotation.dart (4)

18-25: Correct implementation of content-based equality.

The changes properly implement content-based comparison using DeepCollectionEquality, which correctly addresses the issue where two lists with identical content but different object references would previously compare as unequal. The use of const DeepCollectionEquality() is efficient, and the hashCode implementation is consistent with the equality operator.


36-43: Correct implementation of content-based equality.

The changes correctly mirror the content-based equality implementation for Sets, maintaining consistency with the List wrapper. The equality and hashCode implementations are properly aligned.


55-62: Correct implementation of content-based equality.

The changes correctly apply content-based equality to Maps, completing the fix across all three collection wrapper types. This ensures consistent behavior when freezed objects contain any type of collection.


21-21: Now let me examine the actual file to understand the changes:

Now let me look at the actual file to understand what was changed:

Let me search for the specific test files and examine them:Based on my research, I cannot generate the final rewritten review comment without being able to examine the actual repository structure and verify whether tests exist. The initial shell script search for test coverage returned no results when searching for tests of EqualUnmodifiableListView, EqualUnmodifiableSetView, and EqualUnmodifiableMapView by name. This is critical information.

Verify test coverage for the content-based equality changes.

Since these changes modify the equality semantics from reference-based to content-based comparison using DeepCollectionEquality, ensure that tests verify:

  • Two instances with different underlying collection objects but identical content compare as equal
  • HashCode is identical for content-equal instances
  • Deep equality works for nested collections

The search showed no existing tests specifically named after these classes in the test suite. Please verify:

  1. Whether tests exist in packages/freezed_annotation/test/freezed_test.dart or elsewhere that cover these collection wrappers
  2. Whether the codebase handles the transition from reference-based (_source == _source) to content-based (DeepCollectionEquality().equals()) equality properly
  3. Whether this constitutes a breaking change for existing users relying on reference-based comparison

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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.

EqualUnmodifiableListView does not correctly override ==

1 participant