Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
j6carey opened this issue Aug 23, 2022 · 0 comments
Open

Comments

@j6carey
Copy link
Collaborator

j6carey commented Aug 23, 2022

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant