From 8f6fa4b71549c9dd95565a839ff9817ec65b26a8 Mon Sep 17 00:00:00 2001 From: Casper Date: Mon, 19 Oct 2020 13:16:00 -0700 Subject: [PATCH] Updated SupportsAdvancedUnionFeatures to look out for string (#6190) Co-authored-by: Casper Neo --- include/flatbuffers/idl.h | 4 ++++ src/idl_parser.cpp | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/include/flatbuffers/idl.h b/include/flatbuffers/idl.h index d3519e4f1..a28745f0e 100644 --- a/include/flatbuffers/idl.h +++ b/include/flatbuffers/idl.h @@ -438,6 +438,10 @@ struct EnumDef : public Definition { SymbolTable vals; }; +inline bool IsString(const Type &type) { + return type.base_type == BASE_TYPE_STRING; +} + inline bool IsStruct(const Type &type) { return type.base_type == BASE_TYPE_STRUCT && type.struct_def->fixed; } diff --git a/src/idl_parser.cpp b/src/idl_parser.cpp index d2c729a74..b9086840d 100644 --- a/src/idl_parser.cpp +++ b/src/idl_parser.cpp @@ -2998,8 +2998,8 @@ CheckedError Parser::ParseRoot(const char *source, const char **include_paths, for (auto val_it = enum_def.Vals().begin(); val_it != enum_def.Vals().end(); ++val_it) { auto &val = **val_it; - if (!SupportsAdvancedUnionFeatures() && val.union_type.struct_def && - val.union_type.struct_def->fixed) + if (!SupportsAdvancedUnionFeatures() && + (IsStruct(val.union_type) || IsString(val.union_type))) return Error( "only tables can be union elements in the generated language: " + val.name);