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

Generated Go Struct Fields Use Underlying Type Instead of Defined Type If thrift Typedef Comes After

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • 0.12.0, 0.13.0, 0.14.0, 0.15.0
    • None
    • Go - Compiler
    • None

    Description

      When a thrift typedef is placed after a struct in which that typedef is used for a field, the generated Golang code does not assign the defined type but rather the underlying type in its field definition.

       

      Example:

       

      struct MyFirstStruct {
          1: required MyTypedef my_typedef;
      }
      
      typedef i32 MyTypedef;
      
      struct MySecondStruct {
          1: required MyTypedef my_typedef;
      } 

      Generates the code (with elided parts):

      type MyTypedef int32
      
      ...
      
      // Attributes:
      //  - MyTypedef
      type MyFirstStruct struct {
        MyTypedef int32 `thrift:"my_typedef,1,required" db:"my_typedef" json:"my_typedef"`
      }
      
      ...
      
      // Attributes:
      //  - MyTypedef
      type MySecondStruct struct {
        MyTypedef MyTypedef `thrift:"my_typedef,1,required" db:"my_typedef" json:"my_typedef"`
      } 

      Note how the second struct uses the defined type but the first struct uses the underlying type. Since the first struct is able to define the underlying type as the type of the field, it's clearly resolving the typedef but not using it for some reason.

      Attachments

        Activity

          People

            Unassigned Unassigned
            badgerbadgerbadgerbadger Das Shuvomay
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: