@@ -3967,22 +3967,6 @@ void ModuleVisitor::DoAddUse(SourceName location, SourceName localName,
39673967 useProcedure = &useUltimate;
39683968 }
39693969
3970- // Creates a UseErrorDetails symbol in the current scope for a
3971- // current UseDetails symbol, but leaves the UseDetails in the
3972- // scope's name map.
3973- auto CreateLocalUseError{[&]() {
3974- EraseSymbol (*localSymbol);
3975- CHECK (localSymbol->has <UseDetails>());
3976- UseErrorDetails details{localSymbol->get <UseDetails>()};
3977- details.add_occurrence (location, useSymbol);
3978- Symbol *newSymbol{&MakeSymbol (localName, Attrs{}, std::move (details))};
3979- // Restore *localSymbol in currScope
3980- auto iter{currScope ().find (localName)};
3981- CHECK (iter != currScope ().end () && &*iter->second == newSymbol);
3982- iter->second = MutableSymbolRef{*localSymbol};
3983- return newSymbol;
3984- }};
3985-
39863970 // When two derived types arrived, try to combine them.
39873971 const Symbol *combinedDerivedType{nullptr };
39883972 if (!useDerivedType) {
@@ -4008,8 +3992,19 @@ void ModuleVisitor::DoAddUse(SourceName location, SourceName localName,
40083992 combinedDerivedType = localDerivedType;
40093993 } else {
40103994 // Create a local UseErrorDetails for the ambiguous derived type
4011- if (localGeneric) {
4012- combinedDerivedType = CreateLocalUseError ();
3995+ if (localSymbol->has <UseDetails>() && localGeneric) {
3996+ // Creates a UseErrorDetails symbol in the current scope for a
3997+ // current UseDetails symbol, but leaves the UseDetails in the
3998+ // scope's name map.
3999+ UseErrorDetails details{localSymbol->get <UseDetails>()};
4000+ EraseSymbol (*localSymbol);
4001+ details.add_occurrence (location, useSymbol);
4002+ Symbol *newSymbol{&MakeSymbol (localName, Attrs{}, std::move (details))};
4003+ // Restore *localSymbol in currScope
4004+ auto iter{currScope ().find (localName)};
4005+ CHECK (iter != currScope ().end () && &*iter->second == newSymbol);
4006+ iter->second = MutableSymbolRef{*localSymbol};
4007+ combinedDerivedType = newSymbol;
40134008 } else {
40144009 ConvertToUseError (*localSymbol, location, useSymbol);
40154010 localDerivedType = nullptr ;
0 commit comments