[ 
https://issues.apache.org/jira/browse/THRIFT-4901?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16877522#comment-16877522
 ] 

Can Celasun commented on THRIFT-4901:
-------------------------------------

Thanks for the report. As I see it, we have two options:

- Avoid having pointers to pointers (type TThingA testa.ThingA).
- Fix the initialization like:

{code}
tmp := &testa.ThingA{}
p.Value = &tmp
{code}

and dereference at the call site:
{code}
(*p.Value).Write()
{code}

I'd prefer the first one. I might be able to take a look over the weekend. PR 
is welcome of course.

> 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
(v7.6.3#76005)

Reply via email to