You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by "Benoit Sigoure (JIRA)" <ji...@apache.org> on 2017/01/14 22:03:26 UTC

[jira] [Created] (THRIFT-4031) Go plugin generates invalid code for lists of typedef'ed built-in types

Benoit Sigoure created THRIFT-4031:
--------------------------------------

             Summary: 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.4#6332)