diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp index e97f0bf02a515..93fbbb58b06fd 100644 --- a/flang/lib/Semantics/resolve-names.cpp +++ b/flang/lib/Semantics/resolve-names.cpp @@ -3376,7 +3376,8 @@ bool ScopeHandler::CheckPossibleBadForwardRef(const Symbol &symbol) { context().SetError(symbol); return true; } - if ((IsDummy(symbol) || FindCommonBlockContaining(symbol)) && + if ((IsDummy(symbol) || + (!symbol.has() && FindCommonBlockContaining(symbol))) && isImplicitNoneType() && symbol.test(Symbol::Flag::Implicit) && !context().HasError(symbol)) { // Dummy or COMMON was implicitly typed despite IMPLICIT NONE(TYPE) in diff --git a/flang/test/Semantics/bug159977.f90 b/flang/test/Semantics/bug159977.f90 new file mode 100644 index 0000000000000..ee731c9fb170e --- /dev/null +++ b/flang/test/Semantics/bug159977.f90 @@ -0,0 +1,11 @@ +! RUN: %flang_fc1 -fsyntax-only -pedantic %s 2>&1 | FileCheck %s --allow-empty +! Ensure no bogus "no explicit type for ..." error on USE-associated +! implicitly-typed COMMON block object in scope with IMPLICIT NONE. +! CHECK-NOT: error: +module m + common /block/ var +end +subroutine test + use m + implicit none +end