Browse Source

Fix code generation for extensions of a publicly imported message.

If a message A in file A.proto permits extensions,
and file B.proto publicly imports A.proto,
and file C.proto imports B.proto and extends A,
we need to use A to generate the Go struct tag,
but refer to the type alias produced by B,
since C.proto doesn't import A.proto.
David Symonds 10 years ago
parent
commit
bf74a33812
1 changed files with 10 additions and 2 deletions
  1. 10 2
      protoc-gen-go/generator/generator.go

+ 10 - 2
protoc-gen-go/generator/generator.go

@@ -1848,8 +1848,16 @@ func (g *Generator) generateMessage(message *Descriptor) {
 func (g *Generator) generateExtension(ext *ExtensionDescriptor) {
 	ccTypeName := ext.DescName()
 
-	extDesc := g.ObjectNamed(*ext.Extendee).(*Descriptor)
-	extendedType := "*" + g.TypeName(extDesc)
+	extObj := g.ObjectNamed(*ext.Extendee)
+	var extDesc *Descriptor
+	if id, ok := extObj.(*ImportedDescriptor); ok {
+		// This is extending a publicly imported message.
+		// We need the underlying type for goTag.
+		extDesc = id.o.(*Descriptor)
+	} else {
+		extDesc = extObj.(*Descriptor)
+	}
+	extendedType := "*" + g.TypeName(extObj) // always use the original
 	field := ext.FieldDescriptorProto
 	fieldType, wireType := g.GoType(ext.parent, field)
 	tag := g.goTag(extDesc, field, wireType)