reflect/protoreflect: emit valid Go from GoString

Rather than using the <unknown:%d> syntax for GoString,
emit something similar to TypeName(%d),
which is functionally equivalent to casting the integer
to the specified type.

Change-Id: Ibf4bd680d1672fcaba9022fb6bd03bbfe249b8b7
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/191580
Reviewed-by: Herbie Ong <herbie@google.com>
This commit is contained in:
Joe Tsai 2019-08-23 11:41:52 -07:00
parent 72980ee410
commit 6c30280ad6

View File

@ -150,7 +150,7 @@ func (s Syntax) GoString() string {
case Proto3:
return "Proto3"
default:
return fmt.Sprintf("<unknown:%d>", s)
return fmt.Sprintf("Syntax(%d)", s)
}
}
@ -200,7 +200,7 @@ func (c Cardinality) GoString() string {
case Repeated:
return "Repeated"
default:
return fmt.Sprintf("<unknown:%d>", c)
return fmt.Sprintf("Cardinality(%d)", c)
}
}
@ -330,7 +330,7 @@ func (k Kind) GoString() string {
case GroupKind:
return "GroupKind"
default:
return fmt.Sprintf("<unknown:%d>", k)
return fmt.Sprintf("Kind(%d)", k)
}
}