[ 
https://issues.apache.org/jira/browse/THRIFT-2955?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14303939#comment-14303939
 ] 

Jens Geyer commented on THRIFT-2955:
------------------------------------

Against which commit is the patch created? I get an arror with current master:

{code}
error: patch failed: compiler/cpp/src/generate/t_go_generator.cc:154
error: compiler/cpp/src/generate/t_go_generator.cc: patch does not apply
{code}


> Using list of typedefs does not compile on Go
> ---------------------------------------------
>
>                 Key: THRIFT-2955
>                 URL: https://issues.apache.org/jira/browse/THRIFT-2955
>             Project: Thrift
>          Issue Type: Bug
>          Components: Go - Compiler
>    Affects Versions: 0.9.2
>         Environment: Using golang 1.4 on linux/amd64
>            Reporter: Johannes Martinsson
>         Attachments: 0001-Be-explicit-about-when-to-use-true-type.patch
>
>
> 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).
> {code:thrift}
> namespace go poc
> typedef i64 X
> struct Y {
>       1: list<X> xs
> }
> {code}
> I've extracted some of the relevant snippets of code from the generated Go
> code.
> {code: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)
>       }
> }
> {code}
> 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.)



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to