[flang] Fix spurious "already declared" errors for interfaces

When a subroutine or function symbol is defined in an INTERFACE
block, it's okay if a symbol of the same name appears in a
scope between the global scope and the scope of the INTERFACE.

Differential Revision: https://reviews.llvm.org/D103580
This commit is contained in:
peter klausler 2021-06-02 17:33:34 -07:00
parent d515a52a3a
commit 69a82d7c08
1 changed files with 6 additions and 2 deletions

View File

@ -749,8 +749,8 @@ private:
// Edits an existing symbol created for earlier calls to a subprogram or ENTRY
// so that it can be replaced by a later definition.
bool HandlePreviousCalls(const parser::Name &, Symbol &, Symbol::Flag);
// Create a subprogram symbol in the current scope and push a new scope.
void CheckExtantProc(const parser::Name &, Symbol::Flag);
// Create a subprogram symbol in the current scope and push a new scope.
Symbol &PushSubprogramScope(const parser::Name &, Symbol::Flag);
Symbol *GetSpecificFromGeneric(const parser::Name &);
SubprogramDetails &PostSubprogramStmt(const parser::Name &);
@ -3206,7 +3206,11 @@ bool SubprogramVisitor::HandlePreviousCalls(
void SubprogramVisitor::CheckExtantProc(
const parser::Name &name, Symbol::Flag subpFlag) {
if (auto *prev{FindSymbol(name)}) {
if (!IsDummy(*prev) && !HandlePreviousCalls(name, *prev, subpFlag)) {
if (IsDummy(*prev)) {
} else if (inInterfaceBlock() && currScope() != prev->owner()) {
// Procedures in an INTERFACE block do not resolve to symbols
// in scopes between the global scope and the current scope.
} else if (!HandlePreviousCalls(name, *prev, subpFlag)) {
SayAlreadyDeclared(name, *prev);
}
}