Fixed flatc silently accepting non-scalars as default values.
authorWouter van Oortmerssen <wvo@google.com>
Wed, 3 Sep 2014 19:23:15 +0000 (12:23 -0700)
committerWouter van Oortmerssen <wvo@google.com>
Wed, 3 Sep 2014 19:23:15 +0000 (12:23 -0700)
Bug: 17304016
Change-Id: I4873f8ef32fbb2657f15fc53a2c8f767e10f2d96
Tested: on Linux

src/idl_parser.cpp
tests/test.cpp

index 37ff146..9911fab 100644 (file)
@@ -364,6 +364,8 @@ void Parser::ParseField(StructDef &struct_def) {
 
   if (token_ == '=') {
     Next();
+    if (!IsScalar(type.base_type))
+      Error("default values currently only supported for scalars");
     ParseSingleValue(field.value);
   }
 
index edb971a..03955e3 100644 (file)
@@ -489,6 +489,7 @@ void ErrorTest() {
   TestError("union X { Y }", "referenced");
   TestError("union Z { X } struct X { Y:int; }", "only tables");
   TestError("table X { Y:[int]; YLength:int; }", "clash");
+  TestError("table X { Y:string = 1; }", "scalar");
 }
 
 // Additional parser testing not covered elsewhere.