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

Example enum code from documentation does not compile #7343

Open
jmatth opened this issue Mar 31, 2020 · 1 comment
Open

Example enum code from documentation does not compile #7343

jmatth opened this issue Mar 31, 2020 · 1 comment

Comments

@jmatth
Copy link

@jmatth jmatth commented Mar 31, 2020

What version of protobuf and what language are you using?
Version: v3.6.1
Language: N/A

What operating system (Linux, Windows, ...) and version?
Linux (Manjaro)

What runtime / compiler are you using (e.g., python version or gcc version)
N/A

What did you do?
Steps to reproduce the behavior:

  1. Copy the example code for enums with aliases from this documentation to a .proto file, resulting the following contents:
syntax = "proto3";

enum EnumAllowingAlias {
  option allow_alias = true;
  UNKNOWN = 0;
  STARTED = 1;
  RUNNING = 1;
}

enum EnumNotAllowingAlias {
  UNKNOWN = 0;
  STARTED = 1;
  // RUNNING = 1;  // Uncommenting this line will cause a compile error inside Google and a warning message outside.
}
  1. Attempt to compile the proto file with `protoc -oout testfile.proto

What did you expect to see
Code copied directly from the official documentation should compile.

What did you see instead?
Code copied directly from the official documentation fails to compile with the following errors:

test.proto:11:3: "UNKNOWN" is already defined.
test.proto:11:3: Note that enum values use C++ scoping rules, meaning that enum values are siblings of their type, not children of it.  Therefore, "UNKNOWN" must be unique within the global scope, not just within "EnumNotAllowingAlias".
test.proto:12:3: "STARTED" is already defined.
test.proto:12:3: Note that enum values use C++ scoping rules, meaning that enum values are siblings of their type, not children of it.  Therefore, "STARTED" must be unique within the global scope, not just within "EnumNotAllowingAlias".

Make sure you include information that can help us debug (full error message, exception listing, stack trace, logs).

Anything else we should know about your project / environment

@bendanon
Copy link

@bendanon bendanon commented Apr 29, 2020

You can't define two enums with the same values on the global scope. The docs on the page you linked are (now) different than what you quoted, and each enum is in a different message .
When you put each enum in a different message it compiles on 3.11.4 (your code produced the same error you attached).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.