Skip to content

Commit 7037721

Browse files
committed
proto: initialize ExtensionDesc.Type at registration time
When an ExtensionDesc with an uninitialized Type field is registered, initialize the Type. Change-Id: I2c09312e0c4873b7183d0a3c705cddc53d441f1e Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/189161 Reviewed-by: Joe Tsai <[email protected]>
1 parent e7641fa commit 7037721

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

proto/registry.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99
"log"
1010
"reflect"
1111
"strconv"
12+
13+
"google.golang.org/protobuf/runtime/protoimpl"
1214
)
1315

1416
var enumValueMaps = make(map[string]map[string]int32)
@@ -139,6 +141,9 @@ var extensionMaps = make(map[reflect.Type]map[int32]*ExtensionDesc)
139141

140142
// RegisterExtension is called from the generated code.
141143
func RegisterExtension(desc *ExtensionDesc) {
144+
if desc.Type == nil {
145+
desc.Type = protoimpl.X.ExtensionTypeFromDesc(desc)
146+
}
142147
if registerExtensionAlt != nil {
143148
registerExtensionAlt(desc) // populated by hooks_enabled.go
144149
return

0 commit comments

Comments
 (0)