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>
diff --git a/internal/impl/pointer_reflect.go b/internal/impl/pointer_reflect.go
index 055c322..72b782c 100644
--- a/internal/impl/pointer_reflect.go
+++ b/internal/impl/pointer_reflect.go
@@ -51,8 +51,8 @@
// 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
}