Skip to content

Commit aa432c0

Browse files
committed
cmd/protoc-gen-go: fix generation of enum defaults
Previously, this call strconv.FormatInt with base 32, when the intention is to call it with base 10. Change-Id: I31cdd2415b3a80936cdcdeb5612a486204404ecb Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/331149 Trust: Joe Tsai <[email protected]> Reviewed-by: Damien Neil <[email protected]>
1 parent 49b6f72 commit aa432c0

File tree

5 files changed

+1503
-1222
lines changed

5 files changed

+1503
-1222
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,7 @@ func fieldDefaultValue(g *protogen.GeneratedFile, f *fileInfo, m *messageInfo, f
706706
// If the enum value is declared in a different Go package,
707707
// reference it by number since the name may not be correct.
708708
// See https://github.com/golang/protobuf/issues/513.
709-
return g.QualifiedGoIdent(field.Enum.GoIdent) + "(" + strconv.FormatInt(int64(val.Desc.Number()), 32) + ")"
709+
return g.QualifiedGoIdent(field.Enum.GoIdent) + "(" + strconv.FormatInt(int64(val.Desc.Number()), 10) + ")"
710710
}
711711
default:
712712
return "0"

internal/testprotos/enums/enums.pb.go

+159
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/testprotos/enums/enums.proto

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2021 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
syntax = "proto2";
6+
7+
package goproto.proto.enums;
8+
9+
option go_package = "google.golang.org/protobuf/internal/testprotos/enums";
10+
11+
enum Enum {
12+
DEFAULT = 1337;
13+
ZERO = 0;
14+
ONE = 1;
15+
ELEVENT = 11;
16+
SEVENTEEN = 17;
17+
THIRTYSEVEN = 37;
18+
SIXTYSEVEN = 67;
19+
NEGATIVE = -1;
20+
}

0 commit comments

Comments
 (0)