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

Using list of typedefs does not compile on Go



    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 0.9.2
    • 0.9.3
    • Go - Compiler
    • None
    • Using golang 1.4 on linux/amd64


      Using a list with a typedefed value in a struct does not generate compilable
      Go code.

      Here is a small example definition which generates uncompilable code on at
      least 0.9.2 and git master (as of the reporting of this issue).

      Unable to find source-code formatter for language: thrift. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      namespace go poc
      typedef i64 X
      struct Y {
      	1: list<X> xs

      I've extracted some of the relevant snippets of code from the generated Go

      type X int64
      type Y struct {
      	Xs []int64 `thrift:"xs,1" json:"xs"`
      func (p *Y) ReadField1(ipot thrift.TProtocol) error {
      	tSlice := make([]int64, 0, size)
      	for i := 0; i < size; i++ {
      		var _elem0 X
      		// _elem0 declared as X above
      		// [...]
      			temp := X(v)
      			_elem0 = temp
      		// [...]
      		// Trying to append _elem0 (of type X) to p.Xs of type []int64
      		p.Xs = append(p.Xs, _elem0)

      The issue is that the code is trying to append the typedefed type to a list of
      the underlying type. I.e. appending X to a list of int64.

      Smallest code change to make the generated code work is to cast _elem0 to
      int64 in the append operation. However it might be better to actually
      have p.Xs be of type []X rather than []int64.

      (Currently I'm manually patching my generated Go code with type casts before appending to these lists.)


        Issue Links



              jensg Jens Geyer
              axiom Johannes Martinsson
              1 Vote for this issue
              3 Start watching this issue