internal/impl: fix panic message in pointer.AsValueOf

Correctly report the type we were looking for when panicking.
Previously would say: "invalid type: got *T, want *T".

Change-Id: I90ea0dd1fc64f3aec37a5a5828c1832fb0ab2887
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/176258
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
This commit is contained in:
Damien Neil 2019-05-09 12:18:44 -07:00
parent 3eaddf0344
commit 927aaba87c

View File

@ -51,8 +51,8 @@ func (p pointer) Apply(f offset) pointer {
// AsValueOf treats p as a pointer to an object of type t and returns the value.
// It is equivalent to reflect.ValueOf(p.AsIfaceOf(t))
func (p pointer) AsValueOf(t reflect.Type) reflect.Value {
if p.v.Type().Elem() != t {
panic(fmt.Sprintf("invalid type: got %v, want %v", p.v.Type(), t))
if got := p.v.Type().Elem(); got != t {
panic(fmt.Sprintf("invalid type: got %v, want %v", got, t))
}
return p.v
}