protobuf icon indicating copy to clipboard operation
protobuf copied to clipboard

[Proto3] Error compiling reserved values in enum

Open lesliechang opened this issue 8 years ago • 7 comments

According to this documentation for proto3 (https://developers.google.com/protocol-buffers/docs/proto3#enum_reserved), you can add reserved values using the reserved statement, but this no longer compiles.

enum Foo {
  reserved 2, 15, 9 to 11, 40 to max;
  reserved "FOO", "BAR";
}

lesliechang avatar Dec 07 '17 00:12 lesliechang

What's the error message?

xfxyjwf avatar Dec 07 '17 20:12 xfxyjwf

Missing numeric value for enum constant.

lesliechang avatar Dec 07 '17 21:12 lesliechang

Which version were you using? This I believe was first introduced in 3.5.0.

liujisi avatar Dec 07 '17 22:12 liujisi

Confirmed that on 3.5.0, reserved works, however it says "The first enum value must be zero in proto3." So it seems 0 cannot be reserved.

yingzong avatar Mar 19 '18 23:03 yingzong

Why is is that you are saying protobuf version must be >= 3.5.0 when the protobuf documentation shows reserved as a functional keyword for both proto2 and proto3?--as though reserved should have been working long before 3.5.0.

ElectricRCAircraftGuy avatar Nov 19 '19 00:11 ElectricRCAircraftGuy

Sorry for the confusion around this but usually when we talk about proto2 and proto3 we don't mean the version number (like 3.5.0) but instead we are talking about whether you have syntax = "proto2" or syntax = "proto3" at the top of your .proto file. We are actively maintaining both proto2 and proto3, so we have introduced some new proto2 features in 3.x releases.

acozzette avatar Nov 19 '19 17:11 acozzette

I see. That makes sense. Thanks for clarifying this. It would be worth the effort to document it somewhere clearly, perhaps on the readme page or at the tops of the proto2 and proto3 pages I linked to above.

ElectricRCAircraftGuy avatar Nov 20 '19 02:11 ElectricRCAircraftGuy