Yuxuan Wang created THRIFT-5389:
-----------------------------------

             Summary: 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


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 likely also applies to typedef'd types as well.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to