diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp index 35a8c353fcb2..0b0078fa343f 100644 --- a/flang/lib/Semantics/resolve-names.cpp +++ b/flang/lib/Semantics/resolve-names.cpp @@ -6962,16 +6962,18 @@ void ResolveNamesVisitor::CreateGeneric(const parser::GenericSpec &x) { info.Resolve(existing); return; } - if (ultimate.has() || - ultimate.has()) { - genericDetails.set_specific(ultimate); - } else if (ultimate.has()) { - genericDetails.set_derivedType(ultimate); - } else { - SayAlreadyDeclared(symbolName, *existing); - return; + if (&existing->owner() == &currScope()) { + if (ultimate.has() || + ultimate.has()) { + genericDetails.set_specific(ultimate); + } else if (ultimate.has()) { + genericDetails.set_derivedType(ultimate); + } else { + SayAlreadyDeclared(symbolName, *existing); + return; + } + EraseSymbol(*existing); } - EraseSymbol(*existing); } info.Resolve(&MakeSymbol(symbolName, Attrs{}, std::move(genericDetails))); }