jhump/protoreflect

First enum value must be 0 in proto3 [protoprint]

japersik opened this issue · 2 comments

Hi,
I found another invalid case in protoprinter.
If you make a negative identifier in enum (yes, it is possible), then after compiling into a descriptor something like this:

enum MY_ENUM {
    MY_ENUM_UNSPECIFIED = 0;
    MY_ENUM_ONE = 1;
    
    FIELD_NEGATIVE_ID = -1;
}

after using protoprint, it turns into

enum MY_ENUM {
    FIELD_NEGATIVE_ID = -1;
    MY_ENUM_UNSPECIFIED = 0;
    MY_ENUM_ONE = 1;
}

The fields are sorted in ascending order. As a result, we get an invalid proto3 file because First enum value must be 0 in proto3

It reproduce when

protoprint.Printer{
	SortElements: true
}
jhump commented

Fixed in #582