cmd/protoc-gen-go: invert conditional check for proto syntax

To avoid accidentally emitting the UnmarshalMethod in the unlikely
(but possible) event that a proto4 syntax was added, swich the conditional
to only trigger on the proto2 syntax.

Change-Id: I0c201eace56e9ecc92cd791e45ca5d3b99e2ba86
Reviewed-on: https://go-review.googlesource.com/c/154317
Reviewed-by: Damien Neil <dneil@google.com>
This commit is contained in:
Joe Tsai 2018-12-14 12:22:41 -08:00 committed by Joe Tsai
parent d068d302ef
commit 7390346c05

View File

@ -334,7 +334,7 @@ func genEnum(gen *protogen.Plugin, g *protogen.GeneratedFile, f *fileInfo, enum
g.P("}")
g.P()
if enum.Desc.Syntax() != protoreflect.Proto3 {
if enum.Desc.Syntax() == protoreflect.Proto2 {
g.P("func (x *", enum.GoIdent, ") UnmarshalJSON(data []byte) error {")
g.P("value, err := ", f.protoPackage().Ident("UnmarshalJSONEnum"), "(", enum.GoIdent, `_value, data, "`, enum.GoIdent, `")`)
g.P("if err != nil {")