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

Conversation

agreaves
Copy link
Contributor

Treat an empty Map the same as an uninitialized Map when performing equality checks. This ensures that reading a map field does not alter the hashCode or equality comparisons of the message itself.

Treat an empty Map the same as an uninitialized Map when performing equality checks. This ensures that reading a map field does not alter the hashCode or equality comparison of the message itself.
@google-cla
Copy link

google-cla bot commented Mar 23, 2022

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

For more information, open the CLA check for this pull request.

@osa1 osa1 self-assigned this Apr 20, 2022
Copy link
Member

@osa1 osa1 left a comment

Choose a reason for hiding this comment

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

Thanks for the PR. I think this does the right thing given the current representation of default values and uninitialized fields.

I will add a changelog entry for this.

Could you sign the CLA and format the code using dart format please?

We should also add a test since this fixes a bug. A simple repro:

syntax = "proto3";

message Test {
  map<int32, int32> my_map = 1;
}
import '../test.pb.dart';

void main() {
  Test test1 = Test.create();
  Test test2 = Test.create();

  assert(test1 == test2);
  assert(test1.hashCode == test2.hashCode);
  test1.myMap;
  assert(test1 == test2);
  assert(test1.hashCode == test2.hashCode);
}

Feel free to modify one of the existing tests instead. We have a bunch of messages with map fields in the tests that you may be able to reuse.

@osa1
Copy link
Member

osa1 commented May 3, 2022

Closing in favor of #638.

@osa1 osa1 closed this May 3, 2022
@osa1
Copy link
Member

osa1 commented May 16, 2022

Maintainer's note: internally an identical patch was implemented in cl/304375641.

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