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

Referencing constant values doesn't work with with typedef types

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 0.4
    • 0.6
    • Compiler (General)
    • None

    Description

      Setting a constant's value to the value of another constant does not work when the types are typedefs. The workaround is easy, but it devalues the typedef.

      Here's my example input:

      Test.thrift
      // test with strings
      const string str_a = "foo"
      const string str_b = str_a
      
      typedef string MyString
      const MyString mystr_a = "bar"
      const MyString mystr_b = mystr_a // results in empty string
      
      // Test with ints
      const i32 int_x = 42
      const i32 int_y = int_x
      
      typedef i32 MyInt
      const MyInt myint_x = 29
      const MyInt myint_y = myint_x // causes compiler error - code generator ends prematurely
      

      Which erroneously results in the following:

      Constants.java
      public class Constants {
      
          public static final String str_a = "foo";
          public static final String str_b = "foo";
          public static final String mystr_a = "bar";
          public static final String mystr_b = "";
      
          public static final int int_x = 42;
          public static final int int_y = 42;
          public static final int myint_x = 29;
          public static final int 
      <<eof>>
      

      The string typedef fails silently, ignoring the value and using "" instead, while the i32 typedef successfully parses, but causes the code generator to error out mid-file. There are clearly two very different symptoms here, but my gut tells me that they have the same root cause.

      Attachments

        Activity

          People

            dreiss David Reiss
            jdecew Jeff DeCew
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: