internal/impl: weak field bugfixes
Fix a reversed error check in impl.Export{}.WeakNil.
Check to see if we have a type for the weak field on marshal/size.
Treat a typed nil valued in XXX_Weak as not indicating presence for
the field.
Change-Id: Id667ac7eb4f53236be9e181017082bd8cd21d115
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/198717
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
diff --git a/internal/impl/legacy_export.go b/internal/impl/legacy_export.go
index 989e944..cf17794 100644
--- a/internal/impl/legacy_export.go
+++ b/internal/impl/legacy_export.go
@@ -97,8 +97,8 @@
// It panics if the message is not linked into the binary.
func (Export) WeakNil(s pref.FullName) piface.MessageV1 {
mt, err := protoregistry.GlobalTypes.FindMessageByName(s)
- if err == nil {
+ if err != nil {
panic(fmt.Sprintf("weak message %v is not linked in", s))
}
- return reflect.Zero(mt.GoType()).Interface().(piface.MessageV1)
+ return mt.Zero().Interface().(piface.MessageV1)
}