THRIFT-1532 - slightly better fix, take into account requiredness when adding default values

git-svn-id: https://svn.apache.org/repos/asf/thrift/trunk@1303666 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Anthony F. Molinaro 2012-03-22 06:48:33 +00:00
parent 31835148b2
commit 3bba214c13
2 changed files with 21 additions and 5 deletions

View File

@ -588,12 +588,16 @@ void t_erl_generator::generate_erl_struct_member(ostream & out, t_field * tmembe
bool t_erl_generator::has_default_value(t_field * field) { bool t_erl_generator::has_default_value(t_field * field) {
t_type *type = field->get_type(); t_type *type = field->get_type();
if (!field->get_value()) { if (!field->get_value()) {
if ( field->get_req() == t_field::T_REQUIRED) {
if (type->is_struct() || type->is_xception() || type->is_map() || if (type->is_struct() || type->is_xception() || type->is_map() ||
type->is_set() || type->is_list()) { type->is_set() || type->is_list()) {
return true; return true;
} else { } else {
return false; return false;
} }
} else {
return false;
}
} else { } else {
return true; return true;
} }

View File

@ -1,3 +1,8 @@
struct StructB
{
1: string x
}
struct StructA struct StructA
{ {
1: string a, 1: string a,
@ -17,6 +22,13 @@ struct StructA
15: double o = 3.14159, 15: double o = 3.14159,
16: list<string> string_list, 16: list<string> string_list,
17: list<byte> byte_list = [1, 2, 3], 17: list<byte> byte_list = [1, 2, 3],
18: set<string> string_set, 18: required list<string> rsl,
19: map<string, string> string_map 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
} }