diff --git a/flang/lib/Semantics/type.cpp b/flang/lib/Semantics/type.cpp --- a/flang/lib/Semantics/type.cpp +++ b/flang/lib/Semantics/type.cpp @@ -373,8 +373,11 @@ } void InstantiateHelper::InstantiateComponents(const Scope &fromScope) { - for (const auto &pair : fromScope) { - InstantiateComponent(*pair.second); + // Instantiate symbols in declaration order; this ensures that + // parent components and type parameters of ancestor types exist + // by the time that they're needed. + for (SymbolRef ref : fromScope.GetSymbols()) { + InstantiateComponent(*ref); } ComputeOffsets(context(), scope_); } @@ -396,7 +399,7 @@ void Post(const parser::Name &name) { if (name.symbol && name.symbol->has()) { - name.symbol = scope_.FindSymbol(name.source); + name.symbol = scope_.FindComponent(name.source); } }