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

Compiler generates wrong go code for forward defined types in optional fields

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 0.18.0
    • 0.18.1
    • Go - Compiler
    • None

    Description

      This is a bug introduced by the fix of THRIFT-5601.

      Given this thrift file:

      struct Bar {
        1: optional Foo bar
      }
      
      struct Foo {
        1: optional i64 foo
      }
      

      0.18.0 with b39370ec3bc96d2 reverted will generate the following go code (expected):

      ...
      var Bar_Bar_DEFAULT *Foo
      func (p *Bar) GetBar() *Foo {
        if !p.IsSetBar() {
          return Bar_Bar_DEFAULT
        }
      return p.Bar
      }
      ...
      

      while 0.18.0 generates:

      ...
      var Bar_Bar_DEFAULT Foo
      func (p *Bar) GetBar() Foo {
        if !p.IsSetBar() {
          return Bar_Bar_DEFAULT
        }
      return *p.Bar
      }
      ...
      

      This makes usages like bar.GetBar().GetFoo() no longer compiles because GetBar now returns non-pointer type.

      Attachments

        Issue Links

          Activity

            People

              fishywang Yuxuan Wang
              fishywang Yuxuan Wang
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 50m
                  50m