Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
0.9.2
-
None
-
Mac OS X 10.10.2
Thrift 0.9.2 installed via homebrew, and Thrift HEAD (identifies as 1.0.0-dev) installed via homebrew
Description
Motivation
I was attempting to build a go tool that used the Apache Aurora thrift interface, only to be stymied because thrift generates invalid code for the current api.thrift interface. (found under api/src/main/thrift/org/apache/aurora/gen/api.thrift)
Steps to replicate
- Create a thrift file called test.thrift containing the text:
test.thrift
struct Option1 { } struct Option2 { 1: optional string name } union Descendant { 1: Option1 option1 2: Option2 option2 } struct TestStruct { 1: optional Descendant descendant = { "option1": {}} }
- Run thrift -o somedir -r --gen go test.thrift
Expected Result
The command indicates success, and the somedir directory contains a tree of go code that successfully compiles.
Actual Result
The above command outputs
/somedir/gen-go//test/ttypes.go:317:6: expected '}', found ':=' /somedir/gen-go//test/ttypes.go:318:3: expected declaration, found 'IDENT' descendant WARNING - Running 'gofmt -w /somedir/gen-go//test/ttypes.go' failed.
The code fails to compile with similar errors. On inspection, it appears that the go compiler outputs
var TestStruct_Descendant_DEFAULT *Descendant = &Descendant{
v1 := &Option1{}
descendant.Option1 = v1}
which is entirely incorrect. This code should instead be
var TestStruct_Descendant_DEFAULT *Descendant = &Descendant{
Option1: &Option1{}}
When this change is made, the compilation succeeds.