瀏覽代碼

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>
Joe Tsai 7 年之前
父節點
當前提交
7390346c05
共有 1 個文件被更改,包括 1 次插入1 次删除
  1. 1 1
      cmd/protoc-gen-go/internal_gengo/main.go

+ 1 - 1
cmd/protoc-gen-go/internal_gengo/main.go

@@ -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 {")