Skip to content

Commit 59bf49a

Browse files
authored
[flang] Fix bogus error on statement function (#89402)
When a statement function in a nested scope has a name that clashes with a name that exists in the host scope, the compiler can handle it correctly (with a portability warning)... unless the host scope acquired the name via USE association. Fix. Fixes #88678.
1 parent 138524e commit 59bf49a

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

flang/lib/Semantics/resolve-names.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3659,7 +3659,7 @@ bool SubprogramVisitor::HandleStmtFunction(const parser::StmtFunctionStmt &x) {
36593659
misparsedStmtFuncFound_ = true;
36603660
return false;
36613661
}
3662-
if (DoesScopeContain(&ultimate.owner(), currScope())) {
3662+
if (IsHostAssociated(*symbol, currScope())) {
36633663
if (context().ShouldWarn(
36643664
common::LanguageFeature::StatementFunctionExtensions)) {
36653665
Say(name,

flang/test/Semantics/stmt-func02.f90

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
! RUN: %python %S/test_errors.py %s %flang_fc1 -pedantic
2-
module m
2+
module m1
3+
contains
4+
real function rf2(x)
5+
rf2 = x
6+
end
7+
end
8+
module m2
9+
use m1
310
real, target :: x = 1.
411
contains
512
function rpf(x)
@@ -18,7 +25,11 @@ subroutine test1
1825
end
1926
subroutine test2
2027
!PORTABILITY: Name 'rf' from host scope should have a type declaration before its local statement function definition
21-
rf(x) = 3.
28+
rf(x) = 1.
29+
end
30+
subroutine test2b
31+
!PORTABILITY: Name 'rf2' from host scope should have a type declaration before its local statement function definition
32+
rf2(x) = 1.
2233
end
2334
subroutine test3
2435
external sf

0 commit comments

Comments
 (0)