[7392] [cpp] Remove dead code path for map key of type enum in JSON parsing (#16567) #16876
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
[7392] [cpp] Remove dead code path for map key of type enum in JSON parsing (#16567)
Changes
Remove dead code path -- we don't allow enums to be map keys (proto2 spec, proto3 spec). In other words the case block
case FieldDescriptor::TYPE_ENUM
is dead code. Potential enum type keys will be caught indefault: return lex.Invalid("unsupported map key type");
block below similar to other unsupported map key types like double.Motivation
While working on fixing
IgnoreUnknownEnumStringValueInMap
conformance tests for cpp (related issue) I stumbled upon a bug where we pass the wrongfield
parameter to the enum parsing function.In this scope:
field
is a map field of the message that holds the map. This field is not of enum type, it's a repeated message of map entires.key_field
is the key field of the map message entry. This field is the enum type that we need to parse here.The function is long, so I clarified it here:
The correct reference should be
key_field
.Instead of fixing the bug and leaving the dead code, it's better to remove the dead block alltogether.
Closes #16567
COPYBARA_INTEGRATE_REVIEW=#16567 from noom:anton--7392--fix-map-key-nit d992b8a
FUTURE_COPYBARA_INTEGRATE_REVIEW=#16567 from noom:anton--7392--fix-map-key-nit d992b8a