Index: flang/lib/Semantics/resolve-names.cpp =================================================================== --- flang/lib/Semantics/resolve-names.cpp +++ flang/lib/Semantics/resolve-names.cpp @@ -2698,15 +2698,23 @@ // symbol must be either a Use or a Generic formed by merging two uses. // Convert it to a UseError with this additional location. -static void ConvertToUseError( +static bool ConvertToUseError( Symbol &symbol, const SourceName &location, const Scope &module) { const auto *useDetails{symbol.detailsIf()}; if (!useDetails) { - auto &genericDetails{symbol.get()}; - useDetails = &genericDetails.uses().at(0)->get(); + if (auto *genericDetails{symbol.detailsIf()}) { + if (!genericDetails->uses().empty()) { + useDetails = &genericDetails->uses().at(0)->get(); + } + } + } + if (useDetails) { + symbol.set_details( + UseErrorDetails{*useDetails}.add_occurrence(location, module)); + return true; + } else { + return false; } - symbol.set_details( - UseErrorDetails{*useDetails}.add_occurrence(location, module)); } // If a symbol has previously been USE-associated and did not appear in a USE @@ -2807,9 +2815,7 @@ } } if (!combine) { - if (localSymbol.has() || localSymbol.has()) { - ConvertToUseError(localSymbol, location, *useModuleScope_); - } else { + if (!ConvertToUseError(localSymbol, location, *useModuleScope_)) { Say(location, "Cannot use-associate '%s'; it is already declared in this scope"_err_en_US, localName)