-
Type:
Bug
-
Status: Closed
-
Priority:
Critical
-
Resolution: Fixed
-
Affects Version/s: 0.10.0
-
Fix Version/s: 0.11.0
-
Component/s: Go - Compiler
-
Labels:None
-
Environment:
Thrift version 0.10.0
go version go1.7.4 linux/386
Reproduction:
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
Then try to compile the resulting go build _build/pkg/test.go and you'll get:
_build/pkg/test.go:81: cannot use _elem0 (type int32) as type Foo in append
Here's the generated code with line numbers and a couple comments I added:
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 }
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.
- depends upon
-
THRIFT-2955 Using list of typedefs does not compile on Go
-
- Closed
-
- links to