awakesecurity / proto3-suite

Haskell Protobuf Implementation
https://hackage.haskell.org/package/proto3-suite
Other
81 stars 56 forks source link

compile-proto-file should not scope enumerators to their enumeration #222

Open j6carey opened 2 years ago

j6carey commented 2 years ago

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