thrift-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Can Celasun (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (THRIFT-4031) Go plugin generates invalid code for lists of typedef'ed built-in types
Date Wed, 22 Feb 2017 21:05:44 GMT

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

Can Celasun commented on THRIFT-4031:
-------------------------------------

[~jensg] Sounds like a plan. I'll take a shot at this over the weekend and if I end up with
something decent, I'll post a PR and we can discuss it further.

> Go plugin generates invalid code for lists of typedef'ed built-in types
> -----------------------------------------------------------------------
>
>                 Key: THRIFT-4031
>                 URL: https://issues.apache.org/jira/browse/THRIFT-4031
>             Project: Thrift
>          Issue Type: Bug
>          Components: Go - Compiler
>    Affects Versions: 0.10.0
>         Environment: Thrift version 0.10.0
> go version go1.7.4 linux/386
>            Reporter: Benoit Sigoure
>            Priority: Critical
>
> Reproduction:
> {code}
> mkdir /tmp/bug
> cd /tmp/bug
> cat >test.thrift <<EOF
> typedef i32 foo
> struct s {
>  1:list<foo> a
> }
> EOF
> mkdir _build
> thrift -out _build --gen go:package=pkg -r test.thrift
> {code}
> Then try to compile the resulting {{go build _build/pkg/test.go}} and you'll get:
> {code}
> _build/pkg/test.go:81: cannot use _elem0 (type int32) as type Foo in append
> {code}
> Here's the generated code with line numbers and a couple comments I added:
> {code}
>      67 func (p *S)  ReadField1(iprot thrift.TProtocol) error {
>      68   _, size, err := iprot.ReadListBegin()
>      69   if err != nil {
>      70     return thrift.PrependError("error reading list begin: ", err)
>      71   }
>      72   tSlice := make([]Foo, 0, size)  // The slice contain Foo values
>      73   p.A =  tSlice
>      74   for i := 0; i < size; i ++ {
>      75 var _elem0 int32
>      76     if v, err := iprot.ReadI32(); err != nil {
>      77     return thrift.PrependError("error reading field 0: ", err)
>      78 } else {
>      79     _elem0 = v
>      80 }
>      81     p.A = append(p.A, _elem0)  // Here the code should do append(p.A, Foo(_elem0))
>      82   }
>      83   if err := iprot.ReadListEnd(); err != nil {
>      84     return thrift.PrependError("error reading list end: ", err)
>      85   }
>      86   return nil
>      87 }
> {code}
> This was working fine with 0.9.3 so this is a regression in 0.10.0.  With 0.9.3 the slice
{{tSlice}} is a {{[]int32}}, as opposed to a {{[]Foo}}.



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

Mime
View raw message