Details
-
Bug
-
Status: Reopened
-
Major
-
Resolution: Unresolved
-
0.17.0, 0.18.1
-
None
-
None
Description
Currently if a typedef happens after it's first used, the compiler will generate incorrect (uncompilable) go code.
For example, for this thrift file:
struct Bar { 1: optional Foo foo, } typedef i32 Foo
The generated go code would be:
... type Foo int32 ... type Bar struct { Foo *int32 `thrift:"foo,1" db:"foo" json:"foo,omitempty"` } ... func (p *Bar) ReadField1(ctx context.Context, iprot thrift.TProtocol) error { if v, err := iprot.ReadI32(ctx); err != nil { return thrift.PrependError("error reading field 1: ", err) } else { temp := Foo(v) p.Foo = &temp } return nil }
If we move the typedef to be before it's used, then generated go code would be:
... type Bar struct { Foo *Foo `thrift:"foo,1" db:"foo" json:"foo,omitempty"` } ...
instead.
Interestingly the compiler knows that the field should be of type int32 (if we change the typedef to string it would be string instead), so it's not like the compiler don't know about the typedef at all, it's just not using the correct typedef in the go code.
Attachments
Issue Links
- breaks
-
THRIFT-5685 Compiler generates wrong go code for forward defined types in optional fields
- Closed
- relates to
-
THRIFT-3705 Go map has incorrect types when used with forward-defined types
- Closed
- links to