Uploaded image for project: 'Thrift'
  1. Thrift
  2. THRIFT-3051

Go Thrift generator creates bad go code

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 0.9.2
    • 0.9.3
    • Go - Compiler
    • None
    • Mac OS X 10.10.2
      Thrift 0.9.2 installed via homebrew, and Thrift HEAD (identifies as 1.0.0-dev) installed via homebrew

    Description

      Motivation

      I was attempting to build a go tool that used the Apache Aurora thrift interface, only to be stymied because thrift generates invalid code for the current api.thrift interface. (found under api/src/main/thrift/org/apache/aurora/gen/api.thrift)

      Steps to replicate

      1. Create a thrift file called test.thrift containing the text:
        test.thrift
        struct Option1 {
        }
        
        struct Option2 {
          1: optional string name
        }
        
        union Descendant {
          1: Option1 option1
          2: Option2 option2
        }
        
        struct TestStruct {
          1: optional Descendant descendant = { "option1": {}}
        }
        
      2. Run thrift -o somedir -r --gen go test.thrift

      Expected Result

      The command indicates success, and the somedir directory contains a tree of go code that successfully compiles.

      Actual Result

      The above command outputs

      /somedir/gen-go//test/ttypes.go:317:6: expected '}', found ':='
      /somedir/gen-go//test/ttypes.go:318:3: expected declaration, found 'IDENT' descendant
      WARNING - Running 'gofmt -w /somedir/gen-go//test/ttypes.go' failed.
      

      The code fails to compile with similar errors. On inspection, it appears that the go compiler outputs

      ttypes.go
      var TestStruct_Descendant_DEFAULT *Descendant = &Descendant{
        v1 := &Option1{}
        descendant.Option1 = v1}
      

      which is entirely incorrect. This code should instead be

      ttypes.go
      var TestStruct_Descendant_DEFAULT *Descendant = &Descendant{
       Option1: &Option1{}}
      

      When this change is made, the compilation succeeds.

      Attachments

        1. THRIFT-3051.patch
          5 kB
          Jake Farrell

        Activity

          People

            jfarrell Jake Farrell
            swsnider Silas Snider
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: