Skip to content

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

@j6carey

Description

@j6carey

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions