Fixed flatc silently accepting non-scalars as default values.

Bug: 17304016
Change-Id: I4873f8ef32fbb2657f15fc53a2c8f767e10f2d96
Tested: on Linux
This commit is contained in:
Wouter van Oortmerssen 2014-09-03 12:23:15 -07:00
parent 766d0df797
commit 15dc1a86cd
2 changed files with 3 additions and 0 deletions

View 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);
}

View 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.