mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-01 19:58:15 +00:00
chore: emit more reasonable error message when using incomplete type in struct (#7678)
Co-authored-by: Derek Bailey <derekbailey@google.com>
This commit is contained in:
@@ -473,6 +473,10 @@ inline bool IsStruct(const Type &type) {
|
|||||||
return type.base_type == BASE_TYPE_STRUCT && type.struct_def->fixed;
|
return type.base_type == BASE_TYPE_STRUCT && type.struct_def->fixed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline bool IsIncompleteStruct(const Type &type) {
|
||||||
|
return type.base_type == BASE_TYPE_STRUCT && type.struct_def->predecl;
|
||||||
|
}
|
||||||
|
|
||||||
inline bool IsTable(const Type &type) {
|
inline bool IsTable(const Type &type) {
|
||||||
return type.base_type == BASE_TYPE_STRUCT && !type.struct_def->fixed;
|
return type.base_type == BASE_TYPE_STRUCT && !type.struct_def->fixed;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -918,6 +918,12 @@ CheckedError Parser::ParseField(StructDef &struct_def) {
|
|||||||
ECHECK(ParseType(type));
|
ECHECK(ParseType(type));
|
||||||
|
|
||||||
if (struct_def.fixed) {
|
if (struct_def.fixed) {
|
||||||
|
if (IsIncompleteStruct(type) ||
|
||||||
|
(IsArray(type) && IsIncompleteStruct(type.VectorType()))) {
|
||||||
|
std::string type_name = IsArray(type) ? type.VectorType().struct_def->name : type.struct_def->name;
|
||||||
|
return Error(std::string("Incomplete type in struct is not allowed, type name: ") + type_name);
|
||||||
|
}
|
||||||
|
|
||||||
auto valid = IsScalar(type.base_type) || IsStruct(type);
|
auto valid = IsScalar(type.base_type) || IsStruct(type);
|
||||||
if (!valid && IsArray(type)) {
|
if (!valid && IsArray(type)) {
|
||||||
const auto &elem_type = type.VectorType();
|
const auto &elem_type = type.VectorType();
|
||||||
|
|||||||
Reference in New Issue
Block a user