Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 13 additions & 18 deletions flang/lib/Semantics/resolve-names.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3967,22 +3967,6 @@ void ModuleVisitor::DoAddUse(SourceName location, SourceName localName,
useProcedure = &useUltimate;
}

// Creates a UseErrorDetails symbol in the current scope for a
// current UseDetails symbol, but leaves the UseDetails in the
// scope's name map.
auto CreateLocalUseError{[&]() {
EraseSymbol(*localSymbol);
CHECK(localSymbol->has<UseDetails>());
UseErrorDetails details{localSymbol->get<UseDetails>()};
details.add_occurrence(location, useSymbol);
Symbol *newSymbol{&MakeSymbol(localName, Attrs{}, std::move(details))};
// Restore *localSymbol in currScope
auto iter{currScope().find(localName)};
CHECK(iter != currScope().end() && &*iter->second == newSymbol);
iter->second = MutableSymbolRef{*localSymbol};
return newSymbol;
}};

// When two derived types arrived, try to combine them.
const Symbol *combinedDerivedType{nullptr};
if (!useDerivedType) {
Expand All @@ -4008,8 +3992,19 @@ void ModuleVisitor::DoAddUse(SourceName location, SourceName localName,
combinedDerivedType = localDerivedType;
} else {
// Create a local UseErrorDetails for the ambiguous derived type
if (localGeneric) {
combinedDerivedType = CreateLocalUseError();
if (localSymbol->has<UseDetails>() && localGeneric) {
// Creates a UseErrorDetails symbol in the current scope for a
// current UseDetails symbol, but leaves the UseDetails in the
// scope's name map.
UseErrorDetails details{localSymbol->get<UseDetails>()};
EraseSymbol(*localSymbol);
details.add_occurrence(location, useSymbol);
Symbol *newSymbol{&MakeSymbol(localName, Attrs{}, std::move(details))};
// Restore *localSymbol in currScope
auto iter{currScope().find(localName)};
CHECK(iter != currScope().end() && &*iter->second == newSymbol);
iter->second = MutableSymbolRef{*localSymbol};
combinedDerivedType = newSymbol;
} else {
ConvertToUseError(*localSymbol, location, useSymbol);
localDerivedType = nullptr;
Expand Down
28 changes: 28 additions & 0 deletions flang/test/Semantics/bug168099.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
!RUN: %python %S/test_errors.py %s %flang_fc1
module m1
type pair
end type
interface pair
module procedure f
end interface
contains
type(pair) function f(n)
integer, intent(in) :: n
f = pair()
end
end
module m2
type pair
end type
end
module m3
type pair
end type
end
program main
use m1
use m2
use m3
!ERROR: Reference to 'pair' is ambiguous
type(pair) error
end
Loading