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

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

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Cannot Reproduce
    • Affects Version/s: 0.10.0
    • Fix Version/s: 0.14.0
    • Component/s: Compiler (General)
    • Labels:
      None
    • Environment:

      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

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

                Dates

                • Created:
                  Updated:
                  Resolved: