Propagate boolean default values from proto to fbs (#5964)
authorMika Raento <mikie@google.com>
Thu, 11 Jun 2020 17:15:19 +0000 (20:15 +0300)
committerGitHub <noreply@github.com>
Thu, 11 Jun 2020 17:15:19 +0000 (10:15 -0700)
src/idl_parser.cpp

index 4749f36..af74610 100644 (file)
@@ -2608,10 +2608,13 @@ CheckedError Parser::ParseProtoFields(StructDef *struct_def, bool isextend,
           auto val = attribute_;
           ECHECK(ParseProtoCurliesOrIdent());
           if (key == "default") {
-            // Temp: skip non-numeric defaults (enums).
+            // Temp: skip non-numeric and non-boolean defaults (enums).
             auto numeric = strpbrk(val.c_str(), "0123456789-+.");
-            if (IsScalar(type.base_type) && numeric == val.c_str())
+            if (IsScalar(type.base_type) && numeric == val.c_str()) {
               field->value.constant = val;
+            } else if (val == "true") {
+              field->value.constant = val;
+            }  // "false" is default, no need to handle explicitly.
           } else if (key == "deprecated") {
             field->deprecated = val == "true";
           }