proto3-suite
proto3-suite copied to clipboard
compile-proto-file should not scope enumerators to their enumeration
Consider this file test.proto
:
syntax = "proto3";
package Test;
enum E { A = 0; }
enum F { A = 0; }
It is rejected by protoc
:
$ protoc --cpp_out=. test.proto
test.proto:5:10: "A" is already defined in "Test".
test.proto:5:10: Note that enum values use C++ scoping rules, meaning that enum values are siblings of their type, not children of it. Therefore, "A" must be unique within "Test", not just within "F".
NOTE: Using --python_out
or --scala_out
does not eliminate the mention of C++. Probably this rule is imposed regardless of output language.
However, compile-proto-file
accepts it:
compile-proto-file/build/compile-proto-file/compile-proto-file --includeDir . --proto test.proto --out .
The result includes these definitions:
$ grep 'data.*A' Test.hs
data E = EA
data F = FA
Suggestion: For compatibility, compile-proto-file
should impose this rule. And once the rule is imposed, the enumeration type name can be removed from the data constructor:
data E = A