Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix the equality parity issue
  • Loading branch information
TekExplorer committed Aug 27, 2025
commit bcbb92773ad6037846035e3fb39fc1c0a2077302
4 changes: 3 additions & 1 deletion packages/riverpod/lib/src/core/mutations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -516,9 +516,11 @@ final class MutationImpl<ResultT>
);
}

bool _matchesT(Mutation<Object?> other) => other is Mutation<ResultT>;

@override
bool operator ==(Object other) {
if (other is! MutationImpl<ResultT>) return false;
if (other is! MutationImpl<ResultT> || !other._matchesT(this)) return false;
if (_key != null) return _key == other._key;

return super == other;
Expand Down
6 changes: 6 additions & 0 deletions packages/riverpod/test/feature/mutation_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,17 @@ void main() {
final mut = Mutation<num>();
final mutInt = mut<int>(null);
final mutDouble = mut<double>(null);

final confusingMut = mut<num>(null);
// none should be equal
expect(mut, isNot(mutInt));
expect(mut, isNot(mutDouble));
expect(mutInt, isNot(mutDouble));

// check for type equality parity
expect(confusingMut, isNot(mutInt));
expect(mutInt, isNot(confusingMut));

// shows that using the same generic
// with the same key will get the correct value
expect(mutInt, equals(mut<int>(null)));
Expand Down