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

Go generator assigns strings to field in const instead of pointers.

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 0.10.0
    • Fix Version/s: 0.12.0
    • Component/s: Go - Compiler
    • Labels:
      None
    • Environment:

      Generated using docker-thrift.

      Description

      Given the follow thrift definition:

      struct custom {
        1: required string field_a;
        2: optional string field_b;
      }
      

      with the following constant map defined in the same file:

      const map<i32, custom> custom_map = {
        ...,
        42 : { 'field_a':'www.testa.com', 'field_b':'www.testb.com'},
        ...,
      }
      

      Thrift generates the following go struct in the main

      x.go

      file:

      type Custom struct {
        FieldA string `thrift:"field_a,required" db:"field_a" json:"field_a"`
        FieldB *string `thrift:"field_b,2" db:"field_b" json:"field_b,omitempty"`
      }
      

      with the corresponding assignments in the

       X-consts.go 

      file:

      CUSTOM_MAP = map[int]*Custom {
        ...,
        42: &Custom {FieldA: "www.testa.com", FieldB: "www.testb.com"},
        ...,
      }
      

      I assume field_b's pointer type is to allow for null values as per the optional. The generator should be assigning pointers instead of strings.

      I'm not sure how much effort it would take to fix this. I am encountering this problem at work right and would be very happy to starting working on this with some guidance from experts around here.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                jking3 James E. King III
                Reporter:
                DavinC Davin Chia
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: