Skip to content

Message FieldNameEntry not allowed as map value type for field_name #9520

Open
@ergl

Description

@ergl

What version of protobuf and what language are you using?
Version: stable 3.19.4
Language: N/A

What operating system (Linux, Windows, ...) and version?

macOS 11.6.4

What runtime / compiler are you using (e.g., python version or gcc version)

N/A, happens before language-specifc code generation

What did you do?

Steps to reproduce the behavior:

  1. Attempt to use a message with a name of FieldNameEntry as a map value in field field_name

  2. See protoc return the error: map_entry should not be set explicitly. Use map<KeyType, ValueType> instead.

Minimal declaration:

syntax = "proto3"; // also happens on proto2

message AEntry {}

message Container {
    map<uint32, AEntry> a = 1;
}

What did you expect to see

I expected the declaration above to compile cleanly and with no errors.

What did you see instead?

The compiler emits map_entry should not be set explicitly. Use map<KeyType, ValueType> instead. before reaching any language-specific generator.

It took me a bit to realize this has to do with backwards compatibility between maps and repeated values, but the error message did not make sense to me at first, and I did not expect protoc to forbid this usage.

If this is an expected error, perhaps it should be documented (apologies if it is already, and I didn't see it)

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions