-
Notifications
You must be signed in to change notification settings - Fork 15.6k
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
Can not define two same enum name in the same proto file #5425
Comments
This behavior is actually expected. The enum values go into the scope enclosing the whole enum definition, so in cases like your example, values in different enums can still conflict with each other. Probably the best way around it is just to put a prefix in front of |
@acozzette |
The general proto syntax has to taken all supported languages into account. |
Isn't it possible to use scoped enums for c++ 11 and implement an option to specify which enums to be used. We mainly use Java and it's seriously utterly stupid that this requires these kinds of hacks. |
Same applies in Go where the enum value gets automatically prefixed with the enum name by the code generator. |
Hi folks, I need to check that if this enum valid?
|
This is necessary because OTHER and STORAGE are duplicated by enum ResourceCategoryDisplayHint, and this violates protobuf rules for enums. protocolbuffers/protobuf#5425
This is necessary because OTHER and STORAGE are duplicated by enum ResourceCategoryDisplayHint, and this violates protobuf rules for enums. protocolbuffers/protobuf#5425
The design looks odd. Prefixing with the enum name sends me back to the old age of programming. |
It is common use case to define UNSPECIFIED/UNKNOWN=0 in enums to avoid undesired defaults, and require explicit values. |
Is there any plans to fix this? Is there any clean workaround for this in 2024? It really doesn't make any sense. |
+1 |
JavaScript projects that use Please fix the current design! |
For the series: things you won't find in the README.md. |
at least remove the prefix if the prefix has the same name as the enum name please, for example: enum PhoneType {
PHONE_TYPE_UNSPECIFIED = 0;
PHONE_TYPE_MOBILE = 1;
PHONE_TYPE_HOME = 2;
PHONE_TYPE_WORK = 3;
} type PhoneType int32
const (
PhoneType_PHONE_TYPE_UNSPECIFIED PhoneType = 0
PhoneType_PHONE_TYPE_MOBILE PhoneType = 1
PhoneType_PHONE_TYPE_HOME PhoneType = 2
PhoneType_PHONE_TYPE_WORK PhoneType = 3
) it repeats PhoneType twice. can't it be just |
It looks like after this issue was closed it went directly into "do not elaborate further" trash bin |
Version: grpc-protobuf 1.14.0
Language: Java
OS: Windows 7
Steps to reproduce the behavior:
Define the following two enum in the same proto file, both TestEnum1 and TestEnum2 have a enum constant named UNKNOWN.
What did you expect to see
The proto will be compiled successfully.
What did you see instead?
I got the following compile error:
"UNKNOWN" is already defined in "xxx".
And it's interesting that we can't define two same enum constant in the same proto file, but protobuf will add a UNRECOGNIZED enum constant to every enum in the Java class generated after compiling.
The text was updated successfully, but these errors were encountered: