Skip to content

Commit 27ee74e

Browse files
tonyliaosscopybara-github
authored andcommitted
Add map test cases to no_field_presence_test.
Maps behave in a very interesting way if they are set to be implicit-presence fields. They present the possibility that the key or value (or both) can be the default zero value. When that happens, access to the key or the value is unaffected. In this case, presence is a bit of a meaningless concept. Zero keys are valid as map indices, and if a map entry is set to zero, it just always exists. Reflection is a little weird too. - If you do reflection on a normal integer field and ask if a zero-valued field exists, it will tell you that it doesn't exist. This is consistent with what "implicit presence" means. - If you do reflection on a zero integer field that happens to be a map key, it will tell you that it exists. Fetching the value of map[0] is equally valid. (Note that this is not exactly *intended*, but it's just hard to change... and this implementation results in simpler gencode.) I'm adding unit tests in no_field_presence_test to cover this quirk. PiperOrigin-RevId: 676268392
1 parent 921b719 commit 27ee74e

File tree

3 files changed

+991
-7
lines changed

3 files changed

+991
-7
lines changed

src/google/protobuf/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1782,6 +1782,7 @@ cc_test(
17821782
":protobuf",
17831783
"@com_google_absl//absl/log:absl_check",
17841784
"@com_google_absl//absl/memory",
1785+
"@com_google_absl//absl/strings",
17851786
"@com_google_absl//absl/strings:cord",
17861787
"@com_google_absl//absl/strings:string_view",
17871788
"@com_google_googletest//:gtest",

0 commit comments

Comments
 (0)