cmd/protoc-gen-go: fix Reset method
The MessageInfo cache, once set, must not be cleared, otherwise
there exists a *messageState value where the MessageInfo value is nil.
Fix the generation of the Reset method to avoid clearing this value.
Change-Id: Ic84ca8b2640a43e967c36993da1ccd3f2b7096c4
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/201478
Reviewed-by: Damien Neil <dneil@google.com>
diff --git a/internal/testprotos/test/test.pb.go b/internal/testprotos/test/test.pb.go
index dc0b124..800551f 100644
--- a/internal/testprotos/test/test.pb.go
+++ b/internal/testprotos/test/test.pb.go
@@ -373,6 +373,11 @@
func (x *TestAllTypes) Reset() {
*x = TestAllTypes{}
+ if protoimpl.UnsafeEnabled {
+ mi := &file_test_test_proto_msgTypes[0]
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ ms.StoreMessageInfo(mi)
+ }
}
func (x *TestAllTypes) String() string {
@@ -1111,6 +1116,11 @@
func (x *TestDeprecatedMessage) Reset() {
*x = TestDeprecatedMessage{}
+ if protoimpl.UnsafeEnabled {
+ mi := &file_test_test_proto_msgTypes[1]
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ ms.StoreMessageInfo(mi)
+ }
}
func (x *TestDeprecatedMessage) String() string {
@@ -1181,6 +1191,11 @@
func (x *ForeignMessage) Reset() {
*x = ForeignMessage{}
+ if protoimpl.UnsafeEnabled {
+ mi := &file_test_test_proto_msgTypes[2]
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ ms.StoreMessageInfo(mi)
+ }
}
func (x *ForeignMessage) String() string {
@@ -1228,6 +1243,11 @@
func (x *TestReservedFields) Reset() {
*x = TestReservedFields{}
+ if protoimpl.UnsafeEnabled {
+ mi := &file_test_test_proto_msgTypes[3]
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ ms.StoreMessageInfo(mi)
+ }
}
func (x *TestReservedFields) String() string {
@@ -1262,6 +1282,11 @@
func (x *TestAllExtensions) Reset() {
*x = TestAllExtensions{}
+ if protoimpl.UnsafeEnabled {
+ mi := &file_test_test_proto_msgTypes[4]
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ ms.StoreMessageInfo(mi)
+ }
}
func (x *TestAllExtensions) String() string {
@@ -1306,6 +1331,11 @@
func (x *OptionalGroupExtension) Reset() {
*x = OptionalGroupExtension{}
+ if protoimpl.UnsafeEnabled {
+ mi := &file_test_test_proto_msgTypes[5]
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ ms.StoreMessageInfo(mi)
+ }
}
func (x *OptionalGroupExtension) String() string {
@@ -1348,6 +1378,11 @@
func (x *RepeatedGroupExtension) Reset() {
*x = RepeatedGroupExtension{}
+ if protoimpl.UnsafeEnabled {
+ mi := &file_test_test_proto_msgTypes[6]
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ ms.StoreMessageInfo(mi)
+ }
}
func (x *RepeatedGroupExtension) String() string {
@@ -1388,6 +1423,11 @@
func (x *TestNestedExtension) Reset() {
*x = TestNestedExtension{}
+ if protoimpl.UnsafeEnabled {
+ mi := &file_test_test_proto_msgTypes[7]
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ ms.StoreMessageInfo(mi)
+ }
}
func (x *TestNestedExtension) String() string {
@@ -1423,6 +1463,11 @@
func (x *TestRequired) Reset() {
*x = TestRequired{}
+ if protoimpl.UnsafeEnabled {
+ mi := &file_test_test_proto_msgTypes[8]
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ ms.StoreMessageInfo(mi)
+ }
}
func (x *TestRequired) String() string {
@@ -1470,6 +1515,11 @@
func (x *TestRequiredForeign) Reset() {
*x = TestRequiredForeign{}
+ if protoimpl.UnsafeEnabled {
+ mi := &file_test_test_proto_msgTypes[9]
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ ms.StoreMessageInfo(mi)
+ }
}
func (x *TestRequiredForeign) String() string {
@@ -1551,6 +1601,11 @@
func (x *TestRequiredGroupFields) Reset() {
*x = TestRequiredGroupFields{}
+ if protoimpl.UnsafeEnabled {
+ mi := &file_test_test_proto_msgTypes[10]
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ ms.StoreMessageInfo(mi)
+ }
}
func (x *TestRequiredGroupFields) String() string {
@@ -1602,6 +1657,11 @@
func (x *TestWeak) Reset() {
*x = TestWeak{}
+ if protoimpl.UnsafeEnabled {
+ mi := &file_test_test_proto_msgTypes[11]
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ ms.StoreMessageInfo(mi)
+ }
}
func (x *TestWeak) String() string {
@@ -1696,6 +1756,11 @@
func (x *TestPackedTypes) Reset() {
*x = TestPackedTypes{}
+ if protoimpl.UnsafeEnabled {
+ mi := &file_test_test_proto_msgTypes[12]
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ ms.StoreMessageInfo(mi)
+ }
}
func (x *TestPackedTypes) String() string {
@@ -1842,6 +1907,11 @@
func (x *TestUnpackedTypes) Reset() {
*x = TestUnpackedTypes{}
+ if protoimpl.UnsafeEnabled {
+ mi := &file_test_test_proto_msgTypes[13]
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ ms.StoreMessageInfo(mi)
+ }
}
func (x *TestUnpackedTypes) String() string {
@@ -1974,6 +2044,11 @@
func (x *TestPackedExtensions) Reset() {
*x = TestPackedExtensions{}
+ if protoimpl.UnsafeEnabled {
+ mi := &file_test_test_proto_msgTypes[14]
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ ms.StoreMessageInfo(mi)
+ }
}
func (x *TestPackedExtensions) String() string {
@@ -2017,6 +2092,11 @@
func (x *TestUnpackedExtensions) Reset() {
*x = TestUnpackedExtensions{}
+ if protoimpl.UnsafeEnabled {
+ mi := &file_test_test_proto_msgTypes[15]
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ ms.StoreMessageInfo(mi)
+ }
}
func (x *TestUnpackedExtensions) String() string {
@@ -2060,6 +2140,11 @@
func (x *FooRequest) Reset() {
*x = FooRequest{}
+ if protoimpl.UnsafeEnabled {
+ mi := &file_test_test_proto_msgTypes[16]
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ ms.StoreMessageInfo(mi)
+ }
}
func (x *FooRequest) String() string {
@@ -2093,6 +2178,11 @@
func (x *FooResponse) Reset() {
*x = FooResponse{}
+ if protoimpl.UnsafeEnabled {
+ mi := &file_test_test_proto_msgTypes[17]
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ ms.StoreMessageInfo(mi)
+ }
}
func (x *FooResponse) String() string {
@@ -2133,6 +2223,11 @@
func (x *WeirdDefault) Reset() {
*x = WeirdDefault{}
+ if protoimpl.UnsafeEnabled {
+ mi := &file_test_test_proto_msgTypes[18]
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ ms.StoreMessageInfo(mi)
+ }
}
func (x *WeirdDefault) String() string {
@@ -2176,6 +2271,11 @@
func (x *TestAllTypes_NestedMessage) Reset() {
*x = TestAllTypes_NestedMessage{}
+ if protoimpl.UnsafeEnabled {
+ mi := &file_test_test_proto_msgTypes[19]
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ ms.StoreMessageInfo(mi)
+ }
}
func (x *TestAllTypes_NestedMessage) String() string {
@@ -2225,6 +2325,11 @@
func (x *TestAllTypes_OptionalGroup) Reset() {
*x = TestAllTypes_OptionalGroup{}
+ if protoimpl.UnsafeEnabled {
+ mi := &file_test_test_proto_msgTypes[20]
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ ms.StoreMessageInfo(mi)
+ }
}
func (x *TestAllTypes_OptionalGroup) String() string {
@@ -2267,6 +2372,11 @@
func (x *TestAllTypes_RepeatedGroup) Reset() {
*x = TestAllTypes_RepeatedGroup{}
+ if protoimpl.UnsafeEnabled {
+ mi := &file_test_test_proto_msgTypes[21]
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ ms.StoreMessageInfo(mi)
+ }
}
func (x *TestAllTypes_RepeatedGroup) String() string {
@@ -2309,6 +2419,11 @@
func (x *TestRequiredGroupFields_OptionalGroup) Reset() {
*x = TestRequiredGroupFields_OptionalGroup{}
+ if protoimpl.UnsafeEnabled {
+ mi := &file_test_test_proto_msgTypes[40]
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ ms.StoreMessageInfo(mi)
+ }
}
func (x *TestRequiredGroupFields_OptionalGroup) String() string {
@@ -2351,6 +2466,11 @@
func (x *TestRequiredGroupFields_RepeatedGroup) Reset() {
*x = TestRequiredGroupFields_RepeatedGroup{}
+ if protoimpl.UnsafeEnabled {
+ mi := &file_test_test_proto_msgTypes[41]
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ ms.StoreMessageInfo(mi)
+ }
}
func (x *TestRequiredGroupFields_RepeatedGroup) String() string {
diff --git a/internal/testprotos/test/test_import.pb.go b/internal/testprotos/test/test_import.pb.go
index d2eb69d..52fba44 100644
--- a/internal/testprotos/test/test_import.pb.go
+++ b/internal/testprotos/test/test_import.pb.go
@@ -75,6 +75,11 @@
func (x *ImportMessage) Reset() {
*x = ImportMessage{}
+ if protoimpl.UnsafeEnabled {
+ mi := &file_test_test_import_proto_msgTypes[0]
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ ms.StoreMessageInfo(mi)
+ }
}
func (x *ImportMessage) String() string {
diff --git a/internal/testprotos/test/test_public.pb.go b/internal/testprotos/test/test_public.pb.go
index 0055855..f718776 100644
--- a/internal/testprotos/test/test_public.pb.go
+++ b/internal/testprotos/test/test_public.pb.go
@@ -22,6 +22,11 @@
func (x *PublicImportMessage) Reset() {
*x = PublicImportMessage{}
+ if protoimpl.UnsafeEnabled {
+ mi := &file_test_test_public_proto_msgTypes[0]
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ ms.StoreMessageInfo(mi)
+ }
}
func (x *PublicImportMessage) String() string {
diff --git a/internal/testprotos/test/weak1/test_weak.pb.go b/internal/testprotos/test/weak1/test_weak.pb.go
index c62ba49..7ec89f2 100644
--- a/internal/testprotos/test/weak1/test_weak.pb.go
+++ b/internal/testprotos/test/weak1/test_weak.pb.go
@@ -24,6 +24,11 @@
func (x *WeakImportMessage1) Reset() {
*x = WeakImportMessage1{}
+ if protoimpl.UnsafeEnabled {
+ mi := &file_test_weak1_test_weak_proto_msgTypes[0]
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ ms.StoreMessageInfo(mi)
+ }
}
func (x *WeakImportMessage1) String() string {
diff --git a/internal/testprotos/test/weak2/test_weak.pb.go b/internal/testprotos/test/weak2/test_weak.pb.go
index e04031c..e3f0380 100644
--- a/internal/testprotos/test/weak2/test_weak.pb.go
+++ b/internal/testprotos/test/weak2/test_weak.pb.go
@@ -24,6 +24,11 @@
func (x *WeakImportMessage2) Reset() {
*x = WeakImportMessage2{}
+ if protoimpl.UnsafeEnabled {
+ mi := &file_test_weak2_test_weak_proto_msgTypes[0]
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ ms.StoreMessageInfo(mi)
+ }
}
func (x *WeakImportMessage2) String() string {