Skip to content

Commit 90441c2

Browse files
T045Taardappel
authored andcommitted
fix check for Enum defaults (google#5292)
fixes google#5288
1 parent cef8f92 commit 90441c2

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

src/idl_parser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -670,11 +670,11 @@ CheckedError Parser::ParseField(StructDef &struct_def) {
670670

671671
if (token_ == '=') {
672672
NEXT();
673+
ECHECK(ParseSingleValue(&field->name, field->value, true));
673674
if (!IsScalar(type.base_type) ||
674675
(struct_def.fixed && field->value.constant != "0"))
675676
return Error(
676677
"default values currently only supported for scalars in tables");
677-
ECHECK(ParseSingleValue(&field->name, field->value, true));
678678
}
679679
if (type.enum_def &&
680680
!type.enum_def->is_union &&

tests/test.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1275,6 +1275,7 @@ void ErrorTest() {
12751275
TestError("table Y {} table X { Y:int; }", "same as table");
12761276
TestError("struct X { Y:string; }", "only scalar");
12771277
TestError("table X { Y:string = \"\"; }", "default values");
1278+
TestError("struct X { a:uint = 42; }", "default values");
12781279
TestError("enum Y:byte { Z = 1 } table X { y:Y; }", "not part of enum");
12791280
TestError("struct X { Y:int (deprecated); }", "deprecate");
12801281
TestError("union Z { X } table X { Y:Z; } root_type X; { Y: {}, A:1 }",

0 commit comments

Comments
 (0)