square / wire

gRPC and protocol buffers for Android, Kotlin, Swift and Java.
https://square.github.io/wire/
Apache License 2.0
4.23k stars 571 forks source link

Error: multiple enums share constant #3053

Closed santhanamk closed 1 month ago

santhanamk commented 1 month ago

I get this error when there are two proto files.

Roughly it is like below:

file1.proto:

enum Test {
   PHONE = 0
}

file2.proto:

enum TestDifferentEnum {
   PHONE = 0
}

The error is: Cause: multiple enums share constant PHONE

I am using wire compiler 5.0.0 If I do this through Android Studio or command line I get this error.

Command line command looks like this:

java -jar $WIRE_COMPILER_JAR \ --proto_path=./app/src/main/proto \ --kotlin_out=$PROTO_DEST_DIR \

If I use protoc this works fine. Is this something that can be fixed?

Thanks for your help.

oldergod commented 1 month ago

This is a limitation in C++ and I believe Protoc also has it. Your files don't reproduce the error you're seeing.

I've written this

enum Test {
  PHONE = 0;
}

enum TestDifferentEnum {
  PHONE = 0;
}

and protoc complains as well

> protoc: stdout: . stderr: squareup/proto3/kotlin/file1.proto:6:3: "PHONE" is already defined.
  squareup/proto3/kotlin/file1.proto:6:3: Note that enum values use C++ scoping rules, meaning that enum values are siblings of their type, not children of it.  Therefore, "PHONE" must be unique within the global scope, not just within "TestDifferentEnum".