[ https://issues.apache.org/jira/browse/THRIFT-5389?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Yuxuan Wang resolved THRIFT-5389. --------------------------------- Resolution: Fixed > Thrift compiler generates uncompilable go code around optional constants > ------------------------------------------------------------------------ > > Key: THRIFT-5389 > URL: https://issues.apache.org/jira/browse/THRIFT-5389 > Project: Thrift > Issue Type: Bug > Components: Go - Compiler > Affects Versions: 0.14.1 > Reporter: Yuxuan Wang > Assignee: Yuxuan Wang > Priority: Major > Fix For: 0.15.0 > > Time Spent: 20m > Remaining Estimate: 0h > > 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: > {code} > namespace go foo > enum Foo { > One = 1, > Two = 2, > } > struct Bar { > 1: optional Foo foo, > } > const list<Bar> CONSTANTS = [ > { > "foo": Foo.One, > }, > ] > {code} > thrift compiler generated go code: > {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, > }, } > } > {code} > While Bar.Foo is supposed to be a pointer (as it's optional). > This bug also applies to typedef'd types as well: > {code} > namespace go typedefstring > typedef string Foo > struct Struct { > 1: optional Foo foo, > } > const list<Struct> CONSTANTS = [ > { > "foo": "hello", > }, > ] > {code} > {code} > $ 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, > }, } > } > {code} > In const code we try to assign a *string into *Foo field. -- This message was sent by Atlassian Jira (v8.3.4#803005)