diff --git a/src/idl_parser.cpp b/src/idl_parser.cpp index 37ff146cf..9911fab0c 100644 --- a/src/idl_parser.cpp +++ b/src/idl_parser.cpp @@ -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); } diff --git a/tests/test.cpp b/tests/test.cpp index edb971aab..03955e331 100644 --- a/tests/test.cpp +++ b/tests/test.cpp @@ -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.