Uploaded image for project: 'Thrift'
  1. Thrift
  2. THRIFT-4901

Go fails to compile when a struct field is a typedef to a struct

    XMLWordPrintableJSON

    Details

    • Type: Task
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 0.13.0
    • Fix Version/s: None
    • Component/s: Go - Compiler
    • Labels:
      None

      Description

      Given two thrift files:

      # TypedefNamespaceTestA.thrift
      namespace go typedef.namespace.testa
      
      struct ThingA {
        1: bool value
      }
      
      # TypedefNamespaceTestB.thrift
      include "TypedefNamespaceTestA.thrift"
      
      typedef TypedefNamespaceTestA.ThingA TThingA
      
      struct ThingB {
        1: TThingA value
      }
      

      The Thrift Go compiler generates code like:

      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...
      

      This causes the following build failures:

      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)
      

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              johnboiles John Boiles
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated: