diff --git a/src/idl_parser.cpp b/src/idl_parser.cpp index 78072b9ba..b813491ce 100644 --- a/src/idl_parser.cpp +++ b/src/idl_parser.cpp @@ -897,6 +897,29 @@ CheckedError Parser::ParseTable(const StructDef &struct_def, std::string *value, EXPECT(','); } + // Check if all required fields are parsed. + for (auto field_it = struct_def.fields.vec.begin(); + field_it != struct_def.fields.vec.end(); + ++field_it) { + auto required_field = *field_it; + if (!required_field->required) { + continue; + } + bool found = false; + for (auto pf_it = field_stack_.end() - fieldn; + pf_it != field_stack_.end(); + ++pf_it) { + auto parsed_field = pf_it->second; + if (parsed_field == required_field) { + found = true; + break; + } + } + if (!found) { + return Error("required field is missing: " + required_field->name + " in " + struct_def.name); + } + } + if (struct_def.fixed && fieldn != struct_def.fields.vec.size()) return Error("struct: wrong number of initializers: " + struct_def.name);