diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp --- a/flang/lib/Semantics/resolve-names.cpp +++ b/flang/lib/Semantics/resolve-names.cpp @@ -2371,38 +2371,40 @@ const SourceName &localName, Symbol &localSymbol, const Symbol &useSymbol) { localSymbol.attrs() = useSymbol.attrs() & ~Attrs{Attr::PUBLIC, Attr::PRIVATE}; localSymbol.flags() = useSymbol.flags(); + const Symbol &useUltimate{useSymbol.GetUltimate()}; if (auto *useDetails{localSymbol.detailsIf()}) { - const Symbol &ultimate{localSymbol.GetUltimate()}; - if (ultimate == useSymbol.GetUltimate()) { + const Symbol &localUltimate{localSymbol.GetUltimate()}; + if (localUltimate == useUltimate) { // use-associating the same symbol again -- ok - } else if (ultimate.has() && - useSymbol.has()) { + } else if (localUltimate.has() && + useUltimate.has()) { // use-associating generics with the same names: merge them into a // new generic in this scope - auto generic1{ultimate.get()}; - AddGenericUse(generic1, localName, useSymbol); + auto generic1{localUltimate.get()}; + AddGenericUse(generic1, localName, useUltimate); generic1.AddUse(localSymbol); // useSymbol has specific g and so does generic1 - auto &generic2{useSymbol.get()}; + auto &generic2{useUltimate.get()}; if (generic1.derivedType() && generic2.derivedType() && generic1.derivedType() != generic2.derivedType()) { Say(location, "Generic interface '%s' has ambiguous derived types" " from modules '%s' and '%s'"_err_en_US, localSymbol.name(), GetUsedModule(*useDetails).name(), - useSymbol.owner().GetName().value()); + useUltimate.owner().GetName().value()); context().SetError(localSymbol); } else { generic1.CopyFrom(generic2); } EraseSymbol(localSymbol); - MakeSymbol(localSymbol.name(), ultimate.attrs(), std::move(generic1)); + MakeSymbol( + localSymbol.name(), localUltimate.attrs(), std::move(generic1)); } else { ConvertToUseError(localSymbol, location, *useModuleScope_); } } else if (auto *genericDetails{localSymbol.detailsIf()}) { - if (const auto *useDetails{useSymbol.detailsIf()}) { - AddGenericUse(*genericDetails, localName, useSymbol); + if (const auto *useDetails{useUltimate.detailsIf()}) { + AddGenericUse(*genericDetails, localName, useUltimate); if (genericDetails->derivedType() && useDetails->derivedType() && genericDetails->derivedType() != useDetails->derivedType()) { Say(location, diff --git a/flang/lib/Semantics/symbol.cpp b/flang/lib/Semantics/symbol.cpp --- a/flang/lib/Semantics/symbol.cpp +++ b/flang/lib/Semantics/symbol.cpp @@ -431,8 +431,11 @@ }, [&](const UseErrorDetails &x) { os << " uses:"; + char sep{':'}; for (const auto &[location, module] : x.occurrences()) { - os << " from " << module->GetName().value() << " at " << location; + os << sep << " from " << module->GetName().value() << " at " + << location; + sep = ','; } }, [](const HostAssocDetails &) {}, diff --git a/flang/test/Semantics/resolve17.f90 b/flang/test/Semantics/resolve17.f90 --- a/flang/test/Semantics/resolve17.f90 +++ b/flang/test/Semantics/resolve17.f90 @@ -238,3 +238,30 @@ !ERROR: Generic interface 'g' has ambiguous derived types from modules 'm11a' and 'm11b' use m11b end module + +module m12a + interface ga + module procedure sa + end interface +contains + subroutine sa(i) + end +end +module m12b + use m12a + interface gb + module procedure sb + end interface +contains + subroutine sb(x) + end +end +module m12c + use m12b, only: gc => gb +end +module m12d + use m12a, only: g => ga + use m12c, only: g => gc + interface g + end interface +end module