[ https://issues.apache.org/jira/browse/THRIFT-3051?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14387362#comment-14387362 ]
Jens Geyer commented on THRIFT-3051: ------------------------------------ Hi [~swsnider], would it be possible for you to submit a patch or pull request? > Go Thrift generator creates bad go code > --------------------------------------- > > Key: THRIFT-3051 > URL: https://issues.apache.org/jira/browse/THRIFT-3051 > Project: Thrift > Issue Type: Bug > Components: Go - Compiler > Affects Versions: 0.9.2, 1.0 > Environment: 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 > Reporter: Silas Snider > > h2. 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) > h2. Steps to replicate > # Create a thrift file called test.thrift containing the text: > {code:title=test.thrift|borderStyle=solid} > struct Option1 { > } > struct Option2 { > 1: optional string name > } > union Descendant { > 1: Option1 option1 > 2: Option2 option2 > } > struct TestStruct { > 1: optional Descendant descendant = { "option1": {}} > } > {code} > # Run {{thrift -o somedir -r --gen go test.thrift}} > h2. Expected Result > The command indicates success, and the {{somedir}} directory contains a tree > of go code that successfully compiles. > h2. Actual Result > The above command outputs > {code} > /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. > {code} > The code fails to compile with similar errors. On inspection, it appears that > the go compiler outputs > {code:title=ttypes.go|borderStyle=solid} > var TestStruct_Descendant_DEFAULT *Descendant = &Descendant{ > v1 := &Option1{} > descendant.Option1 = v1} > {code} > which is entirely incorrect. This code should instead be > {code:title=ttypes.go|borderStyle=solid} > var TestStruct_Descendant_DEFAULT *Descendant = &Descendant{ > Option1: &Option1{}} > {code} > When this change is made, the compilation succeeds. -- This message was sent by Atlassian JIRA (v6.3.4#6332)