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

Compilation to GO produces broken code

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Critical
    • Resolution: Invalid
    • 0.10.0
    • 0.11.0
    • Go - Compiler
    • None
    • MacOS 10.12.4 (16E195)
      go version go1.8.1 darwin/amd64

    Description

      Sample source file (see attached sample.thrift):

      namespace go reports
      
      typedef string ReportState
      const ReportState ReportStateQueued = "QUEUED";
      const ReportState ReportStateCalculating = "CALCULATING";
      const ReportState ReportStateImporting = "IMPORTING";
      const ReportState ReportStateFinished = "FINISHED";
      const ReportState ReportStateFailed = "FAILED";
      
      struct ReportFilter {
          1: i64 quantity,
          2: i64 dataVersion,
          3: string subscriptionID,
          4: optional string principalID,
          5: optional string createdOn,
          6: optional list<ReportState> states,
      }
      

      after compilation as:

      thrift -r -v -o ./ -out ./go --gen go:package_prefix="git.4tree.de/" ./sample.thrift

      Produces code (see attached sample.go) which contains:

      func (p *ReportFilter)  ReadField6(iprot thrift.TProtocol) error {
        _, size, err := iprot.ReadListBegin()
        if err != nil {
          return thrift.PrependError("error reading list begin: ", err)
        }
        tSlice := make([]ReportState, 0, size)
        p.States =  tSlice
        for i := 0; i < size; i ++ {
      var _elem0 string
          if v, err := iprot.ReadString(); err != nil {
          return thrift.PrependError("error reading field 0: ", err)
      } else {
          _elem0 = v
      }
          p.States = append(p.States, _elem0)
        }
        if err := iprot.ReadListEnd(); err != nil {
          return thrift.PrependError("error reading list end: ", err)
        }
        return nil
      }
      

      When trying to compile this code, GO triggers an error:

      cannot use _elem0 (type string) as type ReportState in append
      

      at line:

       p.States = append(p.States, _elem0)
      

      This code compiles normal using thrift 0.9.3

      Attachments

        1. sample-consts.go
          0.7 kB
          Stanislav Baranov
        2. sample.thrift
          0.6 kB
          Stanislav Baranov
        3. sample.go
          10 kB
          Stanislav Baranov
        4. GoUnusedProtection__.go
          0.2 kB
          Stanislav Baranov

        Issue Links

          Activity

            People

              Unassigned Unassigned
              sb_4tree Stanislav Baranov
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: