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

Treat empty and uninitialized Maps the same in equality checks #591

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
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
9 changes: 9 additions & 0 deletions protobuf/lib/src/protobuf/field_set.dart
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,11 @@ class _FieldSet {
// This is because accessing a repeated field automatically creates it.
// We don't want reading a field to change equality comparisons.
if (val is List && val.isEmpty) return true;

// An empty map field is the same as uninitialized.
// This is because accessing a map field automatically creates it.
// We don't want reading a field to change equality comparisons.
if (val is Map && val.isEmpty) return true;

// For now, initialized and uninitialized fields are different.
// TODO(skybrian) consider other cases; should we compare with the
Expand All @@ -659,6 +664,10 @@ class _FieldSet {
if (value is List && value.isEmpty) {
return hash; // It's either repeated or an empty byte array.
}

if (value is Map && value.isEmpty) {
return hash;
}

hash = _HashUtils._combine(hash, fi.tagNumber);
if (_isBytes(fi.type)) {
Expand Down