Skip to content

Commit

Permalink
cmd/protoc-gen-go: fix generation of enum defaults
Browse files Browse the repository at this point in the history
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 <joetsai@digital-static.net>
Reviewed-by: Damien Neil <dneil@google.com>
  • Loading branch information
dsnet committed Jun 27, 2021
1 parent 49b6f72 commit aa432c0
Show file tree
Hide file tree
Showing 5 changed files with 1,503 additions and 1,222 deletions.
2 changes: 1 addition & 1 deletion cmd/protoc-gen-go/internal_gengo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ func fieldDefaultValue(g *protogen.GeneratedFile, f *fileInfo, m *messageInfo, f
// If the enum value is declared in a different Go package,
// reference it by number since the name may not be correct.
// See https://github.com/golang/protobuf/issues/513.
return g.QualifiedGoIdent(field.Enum.GoIdent) + "(" + strconv.FormatInt(int64(val.Desc.Number()), 32) + ")"
return g.QualifiedGoIdent(field.Enum.GoIdent) + "(" + strconv.FormatInt(int64(val.Desc.Number()), 10) + ")"
}
default:
return "0"
Expand Down
159 changes: 159 additions & 0 deletions internal/testprotos/enums/enums.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions internal/testprotos/enums/enums.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright 2021 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

syntax = "proto2";

package goproto.proto.enums;

option go_package = "google.golang.org/protobuf/internal/testprotos/enums";

enum Enum {
DEFAULT = 1337;
ZERO = 0;
ONE = 1;
ELEVENT = 11;
SEVENTEEN = 17;
THIRTYSEVEN = 37;
SIXTYSEVEN = 67;
NEGATIVE = -1;
}
Loading

0 comments on commit aa432c0

Please sign in to comment.