cmd/protoc-gen-go: fix forwarding decls for inf and NaN defaults
Floating-point defaults of -inf, +inf, and NaN must be generated as
vars rather than consts. Fix the forwarding declaration for public
imports of these vars. (Was "const", is now "var".)
Change-Id: Ic6dc90ab7f88378ba477bff39e047de5f5193c35
Reviewed-on: https://go-review.googlesource.com/c/151757
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
diff --git a/cmd/protoc-gen-go/internal_gengo/main.go b/cmd/protoc-gen-go/internal_gengo/main.go
index b305819..53d6458 100644
--- a/cmd/protoc-gen-go/internal_gengo/main.go
+++ b/cmd/protoc-gen-go/internal_gengo/main.go
@@ -172,8 +172,14 @@
GoName: "Default_" + message.GoIdent.GoName + "_" + field.GoName,
}
decl := "const"
- if field.Desc.Kind() == protoreflect.BytesKind {
+ switch field.Desc.Kind() {
+ case protoreflect.BytesKind:
decl = "var"
+ case protoreflect.FloatKind, protoreflect.DoubleKind:
+ f := field.Desc.Default().Float()
+ if math.IsInf(f, -1) || math.IsInf(f, 1) || math.IsNaN(f) {
+ decl = "var"
+ }
}
g.P(decl, " ", defVar.GoName, " = ", defVar)
}