protoreflect icon indicating copy to clipboard operation
protoreflect copied to clipboard

protoparse: ParseFiles allows case insensitive duplicate enum values

Open WillAbides opened this issue 4 years ago • 2 comments

ParseFiles doesn't do the same check as protoc for case-insensitive duplicate enums.

syntax = "proto3";

package a;

enum Success {
  SUCCESS_UNSPECIFIED = 0;
  SUCCESS_unspecified = 1;
}

protoc result:

a.proto:7:3: Enum name SUCCESS_unspecified has the same name as SUCCESS_UNSPECIFIED if you ignore case and strip out the enum name prefix (if any). This is error-prone and can lead to undefined behavior. Please avoid doing this. If you are using allow_alias, please assign the same numeric value to both enums.

This is similar to https://github.com/jhump/protoreflect/issues/358

WillAbides avatar Oct 31 '21 20:10 WillAbides

Ugh, looks like protoc must have some gnarly parsing logic to identify fields that look the same this way :/

It considers all of these to be conflicts, too:

  • SUCCESS_UNSPECIFIED, Unspecified
  • SUCCESS_UNSPECIFIED, successUnSpecified
  • SUCCESS_UNSPECIFIED, ___success___unspecified

jhump avatar Nov 01 '21 17:11 jhump

@WillAbides, what version of protoc were you using?

In version 3.14, this is just a warning, not an error. I was perusing release notes for all versions since 3.14.0 and don't see anything about a change in behavior. Is it possible you were using an older version of protoc?

jhump avatar Feb 05 '22 16:02 jhump