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

Go: thrift compiler generates wrong code for list of aliased type

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Cannot Reproduce
    • 0.10.0
    • 0.14.0
    • Compiler (General)
    • None
    • Linux amd64/Mac OS Sierra

    Description

      Thrift code bellow produced incorrect Go code.
      In the generated code

      var _elem1 int8

      should be

      var _elem1 StatType

      and

      temp := int8(v)

      should be

      temp := StatType(v)

      Thrift:

      typedef i8 StatType
      
      struct SomeStruct {
       1: list<StatType> stats;
      }
      

      Generated code:

      func (p *CSVAnalyzeTaskPayload)  ReadField1(iprot thrift.TProtocol) error {
        _, size, err := iprot.ReadListBegin()
        if err != nil {
          return thrift.PrependError("error reading list begin: ", err)
        }
        tSlice := make([]StatType, 0, size)
        p.Stats =  tSlice
        for i := 0; i < size; i ++ {
      var _elem1 int8
          if v, err := iprot.ReadByte(); err != nil {
          return thrift.PrependError("error reading field 0: ", err)
      } else {
          temp := int8(v)
          _elem1 = temp
      }
          p.Stats = append(p.Stats, _elem1)
        }
        if err := iprot.ReadListEnd(); err != nil {
          return thrift.PrependError("error reading list end: ", err)
        }
        return nil
      }
      

      Attachments

        Issue Links

          Activity

            People

              zeshuai007 Zezeng Wang
              andrii_degtiarov Andrii Degtiarov
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: