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

Erlang records should allow 'undefined' for non-required fields

    XMLWordPrintableJSON

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 0.11.0
    • Fix Version/s: 0.12.0
    • Component/s: Erlang - Compiler
    • Labels:
      None

      Description

      The Erlang records created by the Erlang code generator allow only the type declared by the Thrift definition file. If a field is not required, however, the Erlang record should also allow the value undefined (this is similar to a null value in other languages).

      Erlang includes a tool, dialyzer, that does type analysis of Erlang code. Until Erlang 19, dialyzer implicitly added `undefined` as an allowed type for all record fields, but as of Erlang 19 it no longer does. This means that dialyzer now emits error messages whenever a record is constructed and initial values are not specified for all of its fields.

      So, for example, the following thrift definition

      struct Test {
        1: required i32 a
        2: i32 b
        3: optional i32 c
      }

      currently produced the following Erlang record:

      -record('Test', {'a' :: integer(),
                       'b' :: integer(),
                       'c' :: integer()}).

       However it should produce the following:

      -record('Test', {'a' :: integer(),
                       'b' :: integer() | undefined,
                       'c' :: integer() | undefined}).

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                dhull David Hull
                Reporter:
                dhull David Hull
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: