Details
Bug
- Status: Closed
Major
- Resolution: Fixed
- 0.9.2
-
-
- None
Using golang 1.4 on linux/amd64
Description
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).
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
code.
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.)
Attachments
Attachments
Issue Links
- is broken by
THRIFT-2793 Go compiler produces uncompilable code
- Closed
- is depended upon by
THRIFT-4031 Go plugin generates invalid code for lists of typedef'ed built-in types
- Closed