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

C#: Constants static constructor does not compile

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 0.8, 0.9
    • 0.9.1
    • C# - Compiler
    • None
    • Patch Available

    Description

      The following Thrift IDL does not correctly compile to C# (from test/ConstantsDemo.thrift):

      struct thing {
        1: i32 hello,
        2: i32 goodbye
      }
      
      enum enumconstants {
        ONE = 1,
        TWO = 2
      }
      
      // struct thing2 {
      //   /** standard docstring */
      //   1: enumconstants val = TWO
      // }
      
      typedef i32 myIntType
      const myIntType myInt = 3
      
      //const map<enumconstants,string> GEN_ENUM_NAMES = {ONE : "HOWDY", TWO: "PARTNER"}
      
      const i32 hex_const = 0x0001F
      
      const i32 GEN_ME = -3523553
      const double GEn_DUB = 325.532
      const double GEn_DU = 085.2355
      const string GEN_STRING = "asldkjasfd"
      
      const map<i32,i32> GEN_MAP = { 35532 : 233, 43523 : 853 }
      const list<i32> GEN_LIST = [ 235235, 23598352, 3253523 ]
      
      const map<i32, map<i32, i32>> GEN_MAPMAP = { 235 : { 532 : 53255, 235:235}}
      
      const map<string,i32> GEN_MAP2 = { "hello" : 233, "lkj98d" : 853, 'lkjsdf' : 098325 }
      
      const thing GEN_THING = { 'hello' : 325, 'goodbye' : 325352 }
      
      const map<i32,thing> GEN_WHAT = { 35 : { 'hello' : 325, 'goodbye' : 325352 } }
      
      const set<i32> GEN_SET = [ 235, 235, 53235 ]
      
      exception Blah {
        1:  i32 bing }
      
      exception Gak {}
      
      service yowza {
        void blingity(),
        i32 blangity() throws (1: Blah hoot )
      }
      

      The constructor generated does not use the correct property name, instead using the field name.

      /**
       * Autogenerated by Thrift Compiler (0.8.0)
       *
       * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
       *  @generated
       */
      using System;
      using System.Collections;
      using System.Collections.Generic;
      using System.Text;
      using System.IO;
      using Thrift;
      using Thrift.Collections;
      
      public class Constants
      {
        public static int   public static int hex_const = 31;
        public static int GEN_ME = -3523553;
        public static double GEn_DUB = 325.532;
        public static double GEn_DU = 85.2355;
        public static string GEN_STRING = "asldkjasfd";
        public static Dictionary<int, int> GEN_MAP = new Dictionary<int, int>();
        public static List<int> GEN_LIST = new List<int>();
        public static Dictionary<int, Dictionary<int, int>> GEN_MAPMAP = new Dictionary<int, Dictionary<int, int>>();
        public static Dictionary<string, int> GEN_MAP2 = new Dictionary<string, int>();
        public static thing GEN_THING = new thing();
        public static Dictionary<int, thing> GEN_WHAT = new Dictionary<int, thing>();
        public static THashSet<int> GEN_SET = new THashSet<int>();
        static Constants()
        {
          GEN_MAP[35532] = 233;
          GEN_MAP[43523] = 853;
          GEN_LIST.Add(235235);
          GEN_LIST.Add(23598352);
          GEN_LIST.Add(3253523);
          Dictionary<int, int> tmp0 = new Dictionary<int, int>();
          tmp0[532] = 53255;
          tmp0[235] = 235;
          GEN_MAPMAP[235] = tmp0;
          GEN_MAP2["hello"] = 233;
          GEN_MAP2["lkj98d"] = 853;
          GEN_MAP2["lkjsdf"] = 98325;
          GEN_THING.hello = 325;
          GEN_THING.goodbye = 325352;
          thing tmp1 = new thing();
          tmp1.hello = 325;
          tmp1.goodbye = 325352;
          GEN_WHAT[35] = tmp1;
          GEN_SET.Add(235);
          GEN_SET.Add(235);
          GEN_SET.Add(53235);
        }
      }
      

      I think it should be tmp1.Hello = 325, tmp1.Goodbye = 325352; this is in line with what the Java compiler produces.

      Attachments

        1. 1788.patch
          1 kB
          Carl Yeksigian
        2. 1788-v2.patch
          2 kB
          Carl Yeksigian

        Issue Links

          Activity

            People

              carlyeks Carl Yeksigian
              carlyeks Carl Yeksigian
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: