You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by "Johannes Martinsson (JIRA)" <ji...@apache.org> on 2015/02/02 14:19:34 UTC
[jira] [Updated] (THRIFT-2955) Using list of typedefs does not
compile on Go
[ https://issues.apache.org/jira/browse/THRIFT-2955?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Johannes Martinsson updated THRIFT-2955:
----------------------------------------
Attachment: 0001-Be-explicit-about-when-to-use-true-type.patch
The attached patch seems to work. Would be nice with some input on this, I'm not very confident in regards to this patch.
> 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)