[
https://issues.apache.org/jira/browse/THRIFT-4901?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18112231#comment-18112231
]
Sylwester Lachiewicz commented on THRIFT-4901:
----------------------------------------------
Still reproducible with the 0.24.0 compiler. THRIFT-6197 collects this and four
sibling reports under the one root cause in the Go generator, with the IDL and
the exact compiler errors for a typedef declared after use, a typedef of a
struct, and a typedef of a struct from an included file. Leaving this issue
open; a fix for THRIFT-6197 should close it.
> Go fails to compile when a struct field is a typedef to a struct
> ----------------------------------------------------------------
>
> Key: THRIFT-4901
> URL: https://issues.apache.org/jira/browse/THRIFT-4901
> Project: Thrift
> Issue Type: Task
> Components: Go - Compiler
> Affects Versions: 0.13.0
> Reporter: John Boiles
> Priority: Major
>
> Given two thrift files:
> {code}
> # TypedefNamespaceTestA.thrift
> namespace go typedef.namespace.testa
> struct ThingA {
> 1: bool value
> }
> {code}
> {code}
> # TypedefNamespaceTestB.thrift
> include "TypedefNamespaceTestA.thrift"
> typedef TypedefNamespaceTestA.ThingA TThingA
> struct ThingB {
> 1: TThingA value
> }
> {code}
> The Thrift Go compiler generates code like:
> {code:go}
> type TThingA *testa.ThingA
> type ThingB struct {
> Value *TThingA `thrift:"value,1" db:"value" json:"value"`
> }
> // ...irrelevant code omitted...
> func (p *ThingB) ReadField1(iprot thrift.TProtocol) error {
> p.Value = &testa.ThingA{} // Fails to compile
> if err := p.Value.Read(iprot); err != nil { // Fails to compile
> // ...irrelevant code omitted...
> func (p *ThingB) writeField1(oprot thrift.TProtocol) (err error) {
> if err := oprot.WriteFieldBegin("value", thrift.STRUCT, 1); err != nil {
> return thrift.PrependError(fmt.Sprintf("%T write field begin error
> 1:value: ", p), err) }
> if err := p.Value.Write(oprot); err != nil { // Fails to compile
> return thrift.PrependError(fmt.Sprintf("%T error writing struct: ",
> p.Value), err)
> }
> // ...irrelevant code omitted...
> {code}
> This causes the following build failures:
> {code}
> gopath/src/typedefnamespacetestb/TypedefNamespaceTestB.go:88:11: cannot use
> &testa.ThingA literal (type *testa.ThingA) as type *TThingA in assignment
> gopath/src/typedefnamespacetestb/TypedefNamespaceTestB.go:89:20: p.Value.Read
> undefined (type *TThingA has no field or method Read)
> gopath/src/typedefnamespacetestb/TypedefNamespaceTestB.go:111:20:
> p.Value.Write undefined (type *TThingA has no field or method Write)
> {code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)