Skip to content

Commit aee7056

Browse files
committed
[flang] Silence bogus error on use after IMPORT
When a scope uses an explicit IMPORT statement to import a symbol from the scope's host, it should not emit a bogus error message later if that symbol is used in a specification construct. The code that checks for imports being hidden by local declarations was not allowing for the presence of host association (or USE) indirection symbols in the local scope. Fix by using GetUltimate() before checking for the hidden symbol. Differential Revision: https://reviews.llvm.org/D118747
1 parent bc699ed commit aee7056

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

flang/lib/Semantics/resolve-names.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6769,9 +6769,12 @@ void ResolveNamesVisitor::CheckImports() {
67696769
void ResolveNamesVisitor::CheckImport(
67706770
const SourceName &location, const SourceName &name) {
67716771
if (auto *symbol{FindInScope(name)}) {
6772-
Say(location, "'%s' from host is not accessible"_err_en_US, name)
6773-
.Attach(symbol->name(), "'%s' is hidden by this entity"_en_US,
6774-
symbol->name());
6772+
const Symbol &ultimate{symbol->GetUltimate()};
6773+
if (&ultimate.owner() == &currScope()) {
6774+
Say(location, "'%s' from host is not accessible"_err_en_US, name)
6775+
.Attach(symbol->name(), "'%s' is hidden by this entity"_en_US,
6776+
symbol->name());
6777+
}
67756778
}
67766779
}
67776780

flang/test/Semantics/resolve29.f90

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
! RUN: %python %S/test_errors.py %s %flang_fc1
2-
module m
2+
module m1
33
type t1
44
end type
55
type t3
@@ -42,3 +42,15 @@ subroutine s7()
4242
call s5()
4343
end
4444
end module
45+
module m2
46+
integer, parameter :: ck = kind('a')
47+
end module
48+
program main
49+
use m2
50+
interface
51+
subroutine s0(x)
52+
import :: ck
53+
character(kind=ck) :: x ! no error
54+
end subroutine
55+
end interface
56+
end program

0 commit comments

Comments
 (0)