You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by "Frank Schroeder (JIRA)" <ji...@apache.org> on 2014/11/05 07:27:33 UTC

[jira] [Comment Edited] (THRIFT-2793) Go compiler produces uncompilable code

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

Frank Schroeder edited comment on THRIFT-2793 at 11/5/14 6:26 AM:
------------------------------------------------------------------

Can we move this back to 0.9.2 since this fixes a bug there? I'll try to get a test case ready by next week but if it helps to get it into 0.9.2 then close the ticket without the test case. I'll provide the test case in any case.


was (Author: magiconair):
Can we move this back to 0.9.2 since this fixes a bug there. I'll try to get a test case ready by next week but if it helps to get it into 0.9.2 then close the ticket without the test case. I'll provide the test case in any case.

> Go compiler produces uncompilable code
> --------------------------------------
>
>                 Key: THRIFT-2793
>                 URL: https://issues.apache.org/jira/browse/THRIFT-2793
>             Project: Thrift
>          Issue Type: Bug
>          Components: Go - Compiler
>    Affects Versions: 0.9.2
>         Environment: OSX 10.10
>            Reporter: Frank Schroeder
>            Assignee: Jens Geyer
>             Fix For: 1.0
>
>         Attachments: THRIFT-2793.patch, Thrift2793.thrift
>
>
> The Thrift Go compiler produces wrong code for the following code:
> {code}
> struct A { 1: list<B> b }
> struct B { 1: i64 id }
> {code}
> The abbreviated reader method creates a []B instead of a []*B but still tries to add a &B{}.
> {code}
>  func (p *A) ReadField1(iprot thrift.TProtocol) error {
>      ...
>      tSlice := make([]B, 0, size)
>      ...
>      for i := 0; i < size; i++ {
>          _elem0 := &B{}
>          ...
>          p.B = append(p.B, _elem0)
>      }
>      ...
>  }
> {code}
> The Go compiler message is:
> {code}
> $ go version
> go version go1.3.3 darwin/amd64
> $ go build
> ./ttypes.go:74: cannot use _elem0 (type *B) as type B in append
> {code}
> Moving struct B *above* struct A produces correct code:
> {code}
> struct B { 1: i64 id }
> struct A { 1: list<B> b }
> {code}
> The abbreviated reader method:
> {code}
>  func (p *A) ReadField1(iprot thrift.TProtocol) error {
>      ...
>      tSlice := make([]*B, 0, size)
>      ...
>      for i := 0; i < size; i++ {
>          _elem0 := &B{}
>          ...
>          p.B = append(p.B, _elem0)
>      }
>      ...
>  }
> {code}
> This problem does not occurr with enums since they are aliases for int64. So both versions generate correct code:
> {code}
> struct A { 1: list<B> b }
> enum B { X }
> {code}
> and
> {code}
> enum B { X }
> struct A { 1: list<B> b }
> {code}
> Tested with version 902b7af4c84b8f716668d4d4f10612c16109c09a from https://git-wip-us.apache.org/repos/asf/thrift.git.
> I've built the thrift compiler with the following flags:
> {code}
> PATH=/opt/boxen/homebrew/Cellar/bison27/2.7.1/bin:$PATH ./configure \
>     --without-cpp \
>     --without-qt4 \
>     --without-c_glib \
>     --without-csharp \
>     --without-java \
>     --without-erlang \
>     --without-nodejs \
>     --without-lua \
>     --without-python \
>     --without-perl \
>     --without-php \
>     --without-php_extension \
>     --without-ruby \
>     --without-haskell \
>     --with-go
> {code}
> and generate the thrift stubs as follows: 
> {code}
> ../compiler/cpp/thrift --gen go -out . model.thrift
> {code}
> I'll try to dig a bit through the source of the generator to see whether I can produce a patch.



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