adwinsky / goprotobuf

Automatically exported from code.google.com/p/goprotobuf
Other
0 stars 0 forks source link

go protoc generates incorrect implicit default enum value #43

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

1. create the following definition

enum Status {
  OK = 6
  INVALID =2
}

message Test {
  optional Status status;
}

2. run protoc
(the generated default value for status is 0 instead of OK)

What is the expected output? What do you see instead?

the first enum value defined is the default, regardless of it numeric value.

What version of the product are you using? On what operating system?

Please provide any additional information below.

Original issue reported on code.google.com by patr...@dropbox.com on 30 Aug 2013 at 3:16

GoogleCodeExporter commented 9 years ago
Where do you see it documented that the default default is the first enum value?

If you write
  optional Status status [default=OK] = 1;
then you'll get your desired behaviour.

Original comment by dsymo...@golang.org on 30 Aug 2013 at 3:22

GoogleCodeExporter commented 9 years ago
I know explicitly adding the default option will fix the issue, but that's not 
the point.  When the default is not explicitly defined, c++ / java / python all 
implements the same behavior (i.e. use the first defined values as default).  I 
know a lot of the c++ code within google (for instance, most of ads enums) 
depends on this assumption.  Using go instead of sawzall on logs will fail in 
that case ...

Original comment by patr...@dropbox.com on 30 Aug 2013 at 3:35

GoogleCodeExporter commented 9 years ago
I'm not saying it's wrong. I'm asking where it's documented, if anywhere. 
Matching other implementations is probably fine.

Original comment by dsymo...@golang.org on 30 Aug 2013 at 4:13

GoogleCodeExporter commented 9 years ago
Note that we should probably change the getter, but it can still behave weirdly 
in other regards.

Original comment by dsymo...@golang.org on 30 Aug 2013 at 4:20

GoogleCodeExporter commented 9 years ago
https://developers.google.com/protocol-buffers/docs/proto#optional

Original comment by patr...@dropbox.com on 3 Sep 2013 at 7:48

GoogleCodeExporter commented 9 years ago

Original comment by dsymo...@golang.org on 3 Sep 2013 at 8:35

GoogleCodeExporter commented 9 years ago
This issue was closed by revision 6f1bebb865e8.

Original comment by dsymo...@golang.org on 18 Sep 2013 at 1:42