Make nested flatbuffer lookup consistent. (#4656)

Lookup type of nested flatbuffer field with either raw name or fully qualified name as already done in the parser.
LookupCreateStruct tries both the raw name and the fully qualified one.
Without this, we cannot reference types outside of the current namespace, e.g. in a different module.
This commit is contained in:
smillius
2018-03-05 17:44:14 +01:00
committed by Wouter van Oortmerssen
parent 9ce98dd77d
commit 77b458bee5

View File

@@ -1687,9 +1687,13 @@ class CppGenerator : public BaseGenerator {
auto nested = field.attributes.Lookup("nested_flatbuffer");
if (nested) {
std::string qualified_name =
parser_.current_namespace_->GetFullyQualifiedName(nested->constant);
auto nested_root = parser_.LookupStruct(qualified_name);
std::string qualified_name = nested->constant;
auto nested_root = parser_.LookupStruct(nested->constant);
if (nested_root == nullptr) {
qualified_name = parser_.current_namespace_->GetFullyQualifiedName(
nested->constant);
nested_root = parser_.LookupStruct(qualified_name);
}
assert(nested_root); // Guaranteed to exist by parser.
(void)nested_root;
code_.SetValue("CPP_NAME", TranslateNameSpace(qualified_name));