encoding/protobuf: don't mark a single enum value as default
Issue #5
Change-Id: Icb6e8b5c6c490ea7123e554a9fb86a2b8d8ba624
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/2373
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
diff --git a/encoding/protobuf/parse.go b/encoding/protobuf/parse.go
index 8593aa3..c918fd1 100644
--- a/encoding/protobuf/parse.go
+++ b/encoding/protobuf/parse.go
@@ -582,6 +582,13 @@
}
p.file.Decls = append(p.file.Decls, enum, d)
+ numEnums := 0
+ for _, v := range x.Elements {
+ if _, ok := v.(*proto.EnumField); ok {
+ numEnums++
+ }
+ }
+
// The line comments for an enum field need to attach after the '|', which
// is only known at the next iteration.
var lastComment *proto.Comment
@@ -601,7 +608,10 @@
var e ast.Expr = value
// Make the first value the default value.
if i == 0 {
- e = &ast.UnaryExpr{OpPos: newline, Op: token.MUL, X: value}
+ e = value
+ if numEnums > 1 {
+ e = &ast.UnaryExpr{OpPos: newline, Op: token.MUL, X: value}
+ }
} else {
value.ValuePos = newline
}