Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
0.14.1
-
None
Description
This is essentially the same issue as THRIFT-4253, just the fix of THRIFT-4253 was not complete.
THRIFT-4253 fixed the primitive types, but does not work for enums. Here's a minimal reproducible thrift file:
namespace go foo enum Foo { One = 1, Two = 2, } struct Bar { 1: optional Foo foo, } const list<Bar> CONSTANTS = [ { "foo": Foo.One, }, ]
thrift compiler generated go code:
$ cat gen-go/foo/foo-consts.go // Code generated by Thrift Compiler (0.14.1). DO NOT EDIT. package foo import( "bytes" "context" "fmt" "time" "github.com/apache/thrift/lib/go/thrift" ) // (needed to ensure safety because of naive import list construction.) var _ = thrift.ZERO var _ = fmt.Printf var _ = context.Background var _ = time.Now var _ = bytes.Equal var CONSTANTS []*Bar func init() { CONSTANTS = []*Bar{ &Bar{ Foo: 1, }, } }
While Bar.Foo is supposed to be a pointer (as it's optional).
This bug also applies to typedef'd types as well:
namespace go typedefstring typedef string Foo struct Struct { 1: optional Foo foo, } const list<Struct> CONSTANTS = [ { "foo": "hello", }, ]
$ cat gen-go/typedefstring/typedefstring-consts.go // Code generated by Thrift Compiler (0.14.1). DO NOT EDIT. package typedefstring import( "bytes" "context" "fmt" "time" "github.com/apache/thrift/lib/go/thrift" ) // (needed to ensure safety because of naive import list construction.) var _ = thrift.ZERO var _ = fmt.Printf var _ = context.Background var _ = time.Now var _ = bytes.Equal var CONSTANTS []*Struct func init() { CONSTANTS = []*Struct{ &Struct{ Foo: &(&struct{x string}{"hello"}).x, }, } }
In const code we try to assign a *string into *Foo field.
Attachments
Issue Links
- links to