John Boiles created THRIFT-4901:
-----------------------------------

             Summary: Go fails to compile when a struct field is a typedef to a 
struct
                 Key: THRIFT-4901
                 URL: https://issues.apache.org/jira/browse/THRIFT-4901
             Project: Thrift
          Issue Type: Task
          Components: Go - Compiler
    Affects Versions: 0.13.0
            Reporter: John Boiles


Given two thrift files:

{code}
# TypedefNamespaceTestA.thrift
namespace go typedef.namespace.testa

struct ThingA {
  1: bool value
}
{code}

{code}
# TypedefNamespaceTestB.thrift
include "TypedefNamespaceTestA.thrift"

typedef TypedefNamespaceTestA.ThingA TThingA

struct ThingB {
  1: TThingA value
}
{code}

The Thrift Go compiler generates code like:

{code:go}
type TThingA *testa.ThingA

type ThingB struct {
  Value *TThingA `thrift:"value,1" db:"value" json:"value"`
}

// ...irrelevant code omitted...

func (p *ThingB)  ReadField1(iprot thrift.TProtocol) error {
  p.Value = &testa.ThingA{} // Fails to compile
  if err := p.Value.Read(iprot); err != nil { // Fails to compile

// ...irrelevant code omitted...

func (p *ThingB) writeField1(oprot thrift.TProtocol) (err error) {
  if err := oprot.WriteFieldBegin("value", thrift.STRUCT, 1); err != nil {
    return thrift.PrependError(fmt.Sprintf("%T write field begin error 1:value: 
", p), err) }
  if err := p.Value.Write(oprot); err != nil { // Fails to compile
    return thrift.PrependError(fmt.Sprintf("%T error writing struct: ", 
p.Value), err)
  }

/ ...irrelevant code omitted...
{code}

This causes the following build failures:
{code}
gopath/src/typedefnamespacetestb/TypedefNamespaceTestB.go:88:11: cannot use 
&testa.ThingA literal (type *testa.ThingA) as type *TThingA in assignment
gopath/src/typedefnamespacetestb/TypedefNamespaceTestB.go:89:20: p.Value.Read 
undefined (type *TThingA has no field or method Read)
gopath/src/typedefnamespacetestb/TypedefNamespaceTestB.go:111:20: p.Value.Write 
undefined (type *TThingA has no field or method Write)
{code}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to