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

Go generator does not respect typedef types when generating read/write functions.

VotersWatch issueWatchersLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 0.10.0
    • Fix Version/s: None
    • Component/s: Go - Compiler
    • Labels:
      None

      Description

      Give the following thrift definitions:

      typedef i64   RequestId 
      
      struct Custom {
        optional set<RequestId> field_a;
      }
      

      The following go code is generated:

      type RequestId int64
      
      type Custom struct {
        FieldA map[RequestId]struct{}
      }
      
      ...
      
      func (p *Custom)  ReadField1(iprot thrift.TProtocol) error {
        _, size, err := iprot.ReadSetBegin()
        if err != nil {
          return thrift.PrependError("error reading set begin: ", err)
        }
        tSet := make(map[int64]struct{}, size)
        p.ActiveImportIds =  tSet
        for i := 0; i < size; i ++ {
      var _elem1 int64
          if v, err := iprot.ReadI64(); err != nil {
          return thrift.PrependError("error reading field 0: ", err)
      } else {
          _elem1 = v
      }
          p.FieldA[_elem1] = struct{}{}
        }
        if err := iprot.ReadSetEnd(); err != nil {
          return thrift.PrependError("error reading set end: ", err)
        }
        return nil
      }
      

      There are two errors here:
      1.

      tSet

      should be

       map[RequestId]struct{} 

      and not

      map[int64]struct{}

      .
      2.

       elem_1 

      should be of type

      RequestId

      and the values need to be case to

      RequestId

      before assigning to

      elem_1

      .

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              DavinC Davin Chia

              Dates

              • Created:
                Updated:
                Resolved:

                Issue deployment