mirror of
https://github.com/protocolbuffers/protobuf-go.git
synced 2025-01-04 02:38:50 +00:00
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:
parent
3eaddf0344
commit
927aaba87c
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user