You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by mo...@apache.org on 2012/03/22 07:48:33 UTC

svn commit: r1303666 - in /thrift/trunk: compiler/cpp/src/generate/t_erl_generator.cc lib/erl/test/Thrift1475.thrift

Author: molinaro
Date: Thu Mar 22 06:48:33 2012
New Revision: 1303666

URL: http://svn.apache.org/viewvc?rev=1303666&view=rev
Log:
THRIFT-1532 - slightly better fix, take into account requiredness when adding default values

Modified:
    thrift/trunk/compiler/cpp/src/generate/t_erl_generator.cc
    thrift/trunk/lib/erl/test/Thrift1475.thrift

Modified: thrift/trunk/compiler/cpp/src/generate/t_erl_generator.cc
URL: http://svn.apache.org/viewvc/thrift/trunk/compiler/cpp/src/generate/t_erl_generator.cc?rev=1303666&r1=1303665&r2=1303666&view=diff
==============================================================================
--- thrift/trunk/compiler/cpp/src/generate/t_erl_generator.cc (original)
+++ thrift/trunk/compiler/cpp/src/generate/t_erl_generator.cc Thu Mar 22 06:48:33 2012
@@ -588,9 +588,13 @@ void t_erl_generator::generate_erl_struc
 bool t_erl_generator::has_default_value(t_field * field) {
   t_type *type = field->get_type();
   if (!field->get_value()) {
-    if (type->is_struct() || type->is_xception() || type->is_map() ||
-        type->is_set() || type->is_list()) {
-      return true;
+    if ( field->get_req() == t_field::T_REQUIRED) {
+      if (type->is_struct() || type->is_xception() || type->is_map() ||
+          type->is_set() || type->is_list()) {
+        return true;
+      } else {
+        return false;
+      }
     } else {
       return false;
     }

Modified: thrift/trunk/lib/erl/test/Thrift1475.thrift
URL: http://svn.apache.org/viewvc/thrift/trunk/lib/erl/test/Thrift1475.thrift?rev=1303666&r1=1303665&r2=1303666&view=diff
==============================================================================
--- thrift/trunk/lib/erl/test/Thrift1475.thrift (original)
+++ thrift/trunk/lib/erl/test/Thrift1475.thrift Thu Mar 22 06:48:33 2012
@@ -1,3 +1,8 @@
+struct StructB
+{
+  1: string x
+}
+
 struct StructA
 {
   1: string a,
@@ -17,6 +22,13 @@ struct StructA
   15: double o = 3.14159,
   16: list<string> string_list,
   17: list<byte> byte_list = [1, 2, 3],
-  18: set<string> string_set,
-  19: map<string, string> string_map
+  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
 }