From 90441c207838f611e4459595d3ac57468bcde13a Mon Sep 17 00:00:00 2001 From: Nils Berg Date: Mon, 15 Apr 2019 20:38:44 +0200 Subject: [PATCH] fix check for Enum defaults (#5292) fixes #5288 --- src/idl_parser.cpp | 2 +- tests/test.cpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/idl_parser.cpp b/src/idl_parser.cpp index ba28ae6f2..e26aa5508 100644 --- a/src/idl_parser.cpp +++ b/src/idl_parser.cpp @@ -670,11 +670,11 @@ CheckedError Parser::ParseField(StructDef &struct_def) { if (token_ == '=') { NEXT(); + ECHECK(ParseSingleValue(&field->name, field->value, true)); if (!IsScalar(type.base_type) || (struct_def.fixed && field->value.constant != "0")) return Error( "default values currently only supported for scalars in tables"); - ECHECK(ParseSingleValue(&field->name, field->value, true)); } if (type.enum_def && !type.enum_def->is_union && diff --git a/tests/test.cpp b/tests/test.cpp index 4af297440..4e23d79f0 100644 --- a/tests/test.cpp +++ b/tests/test.cpp @@ -1275,6 +1275,7 @@ void ErrorTest() { TestError("table Y {} table X { Y:int; }", "same as table"); TestError("struct X { Y:string; }", "only scalar"); TestError("table X { Y:string = \"\"; }", "default values"); + TestError("struct X { a:uint = 42; }", "default values"); TestError("enum Y:byte { Z = 1 } table X { y:Y; }", "not part of enum"); TestError("struct X { Y:int (deprecated); }", "deprecate"); TestError("union Z { X } table X { Y:Z; } root_type X; { Y: {}, A:1 }",