internal/impl: fix reversed IsValid test

Change-Id: Iaf5291a6bf31ad3dd130fca06840cec66b896f59
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/211558
Reviewed-by: Joe Tsai <joetsai@google.com>
This commit is contained in:
Damien Neil 2019-12-16 13:23:25 -08:00
parent d65001875f
commit b120a23bc8
3 changed files with 14 additions and 3 deletions

View File

@ -741,7 +741,7 @@ func (m *{{.}}) SetUnknown(b protoreflect.RawFields) {
m.messageInfo().setUnknown(m.pointer(), b)
}
func (m *{{.}}) IsValid() bool {
return m.pointer().IsNil()
return !m.pointer().IsNil()
}
{{end}}

View File

@ -125,7 +125,7 @@ func (m *messageState) SetUnknown(b protoreflect.RawFields) {
m.messageInfo().setUnknown(m.pointer(), b)
}
func (m *messageState) IsValid() bool {
return m.pointer().IsNil()
return !m.pointer().IsNil()
}
func (m *messageReflectWrapper) Descriptor() protoreflect.MessageDescriptor {
@ -245,5 +245,5 @@ func (m *messageReflectWrapper) SetUnknown(b protoreflect.RawFields) {
m.messageInfo().setUnknown(m.pointer(), b)
}
func (m *messageReflectWrapper) IsValid() bool {
return m.pointer().IsNil()
return !m.pointer().IsNil()
}

View File

@ -1437,6 +1437,17 @@ func TestReset(t *testing.T) {
m.Descriptor()
}
func TestIsValid(t *testing.T) {
var m *testpb.TestAllTypes
if got, want := m.ProtoReflect().IsValid(), false; got != want {
t.Errorf("((*M)(nil)).ProtoReflect().IsValid() = %v, want %v", got, want)
}
m = &testpb.TestAllTypes{}
if got, want := m.ProtoReflect().IsValid(), true; got != want {
t.Errorf("(&M{}).ProtoReflect().IsValid() = %v, want %v", got, want)
}
}
// The MessageState implementation makes the assumption that when a
// concrete message is unsafe casted as a *MessageState, the Go GC does
// not reclaim the memory for the remainder of the concrete message.