[ https://issues.apache.org/jira/browse/THRIFT-1532?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13235404#comment-13235404 ]
Anthony Molinaro commented on THRIFT-1532: ------------------------------------------ Actually, made one more minor adjustment which I believe makes it even more correct. Instead of having any complex type (ie, set, list, map, record), require a default value, I only add the defaults if it's a required field (as it should be perfectly correct to have an undefined optional or default field). So this makes my example {code} struct StructB { 1: string x } struct StructA { 1: string a, 2: binary b, 3: optional string c, 4: optional binary d, 5: required string e, 6: required binary f, 7: string g = "foo", 8: i32 h, 9: optional i32 i, 10: required i32 j, 11: required i32 k = 5, 12: double l, 13: optional double m, 14: required double n, 15: double o = 3.14159, 16: list<string> string_list, 17: list<byte> byte_list = [1, 2, 3], 18: required list<string> rsl, 19: optional list<string> osl, 20: set<string> string_set, 21: required set<string> rss, 22: optional set<string> oss, 23: map<string, string> string_map, 24: required map<string, string> rsm, 25: optional map<string, string> osm, 26: StructB structb } {code} Now generate this {code} %% struct structB -record(structB, {x :: string() | binary()}). %% struct structA -record(structA, {a :: string() | binary(), b :: string() | binary(), c :: string() | binary(), d :: string() | binary(), e :: string() | binary(), f :: string() | binary(), g = "foo" :: string() | binary(), h :: integer(), i :: integer(), j :: integer(), k = 5 :: integer(), l :: float(), m :: float(), n :: float(), o = 3.14159 :: float(), string_list :: list(), byte_list = [1,2,3] :: list(), rsl = [] :: list(), osl :: list(), string_set :: set(), rss = sets:new() :: set(), oss :: set(), string_map :: dict(), rsm = dict:new() :: dict(), osm :: dict(), structb :: #structB{}}). {code} Please try it out and let me know how it goes. > The type specifications in the generated Erlang code should include > "undefined" where it's used as a default value > ------------------------------------------------------------------------------------------------------------------ > > Key: THRIFT-1532 > URL: https://issues.apache.org/jira/browse/THRIFT-1532 > Project: Thrift > Issue Type: Improvement > Components: Erlang - Compiler > Affects Versions: 0.8 > Environment: Erlang/OTP R15B. > Reporter: Björn Bylander > Assignee: Anthony Molinaro > Priority: Minor > Labels: compiler, dialyzer, erlang, specification, type > Fix For: 0.9 > > Attachments: THRIFT-1532_t_erl_generator.cc.patch, agent.tar.gz > > Original Estimate: 1h > Remaining Estimate: 1h > > The Erlang code generated by the compiler for, for example, an integer field > of a struct sets a default value of 'undefined' but the type to just > 'integer()' which doesn't include the default value. This makes Dialyzer > complain if the field has not been initialized as it gets set to 'undefined' > instead of an integer value. -- This message is automatically generated by JIRA. If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa For more information on JIRA, see: http://www.atlassian.com/software/jira