-
Notifications
You must be signed in to change notification settings - Fork 382
Fix Map/List/Set equality in generated Dart structs #2956
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
base: master
Are you sure you want to change the base?
Conversation
Generated Dart structs with collection fields (Map, List, Set) were using identity comparison (==) instead of deep equality. This caused equality checks to fail even when collection contents were identical. Fix: - Use DeepCollectionEquality for collection fields in operator== and hashCode - Export DeepCollectionEquality from flutter_rust_bridge_for_generated_common.dart - Handle Optional types wrapping collections
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This pull request fixes a critical bug in generated Dart struct equality checking where collection fields (Map, List, Set) were using identity comparison (==) instead of deep equality comparison. This caused equality checks to fail even when collection contents were identical.
Key Changes:
- Modified code generation logic to use
DeepCollectionEqualityfor collection fields inoperator==andhashCode - Added recursive handling for Optional types wrapping collections
- Exported
DeepCollectionEqualityfrom the common library for generated code
Reviewed changes
Copilot reviewed 29 out of 29 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
frb_codegen/src/library/codegen/generator/api_dart/spec_generator/class/ty/structure_non_freezed.rs |
Core logic change: Added needs_deep_equality() function to detect collection types and generate appropriate equality/hash code using DeepCollectionEquality |
frb_dart/lib/flutter_rust_bridge_for_generated_common.dart |
Exported DeepCollectionEquality from collection package for use in generated code |
frb_example/pure_dart/test/api/mirror_test.dart |
Added tests verifying Map and List equality works correctly for structs with identical contents |
frb_example/pure_dart/lib/src/rust/api/*.dart |
Generated Dart code updated to use DeepCollectionEquality for List/Map/Set fields in equality and hashCode methods |
frb_example/pure_dart/lib/src/rust/api/enumeration.dart |
Code formatting changes (unrelated to equality fix) |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| delegate, | ||
| MirTypeDelegate::Map(_) | MirTypeDelegate::Set(_) | ||
| ), | ||
| MirType::Optional(opt) => needs_deep_equality(&opt.inner), |
Copilot
AI
Dec 31, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The needs_deep_equality function does not handle MirType::Boxed types that wrap collections (List, Map, or Set). If a field has type Box<List<T>>, Box<Map<K,V>>, or Box<Set<T>>, the function will return false and use identity comparison instead of deep equality.
Consider adding a case for MirType::Boxed that recursively checks the inner type, similar to how MirType::Optional is handled.
| MirType::Optional(opt) => needs_deep_equality(&opt.inner), | |
| MirType::Optional(opt) => needs_deep_equality(&opt.inner), | |
| MirType::Boxed(_) => true, |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #2956 +/- ##
===========================================
- Coverage 98.57% 85.19% -13.39%
===========================================
Files 464 464
Lines 19202 18976 -226
===========================================
- Hits 18928 16166 -2762
- Misses 274 2810 +2536 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Great job! However, this seems to be a breaking change, maybe we should add a flag to allow users to enable/disable it. In addition, it seems that users can use |
Generated Dart structs with collection fields (Map, List, Set) were using identity comparison (==) instead of deep equality. This caused equality checks to fail even when collection contents were identical.
Fix:
Changes
Fixes #the-issue-number-here
Procedure and Checklist
In order to quickly iterate and avoid slowing down development pace by making CI pass, only the following simplified steps are needed, and I (fzyzcjy) will handle the rest of CI / moving the tests currently (will have more automation in the future).
frb_example/dart_minimal.dart_minimal's CI green.Utility commands
cargo run --manifest-path /path/to/flutter_rust_bridge/frb_codegen/Cargo.toml -- generate./frb_internal test-dart-native --package frb_example/dart_minimal