diff --git a/flang/lib/Evaluate/check-expression.cpp b/flang/lib/Evaluate/check-expression.cpp --- a/flang/lib/Evaluate/check-expression.cpp +++ b/flang/lib/Evaluate/check-expression.cpp @@ -526,18 +526,14 @@ } else { return "dummy procedure argument"; } + } else if (&symbol.owner() != &scope_ || &ultimate.owner() != &scope_) { + return std::nullopt; // host association is in play } else if (const auto *object{ ultimate.detailsIf()}) { if (object->commonBlock()) { return std::nullopt; } } - for (const semantics::Scope *s{&scope_}; !s->IsGlobal();) { - s = &s->parent(); - if (s == &ultimate.owner()) { - return std::nullopt; - } - } return "reference to local entity '"s + ultimate.name().ToString() + "'"; } diff --git a/flang/lib/Semantics/check-declarations.cpp b/flang/lib/Semantics/check-declarations.cpp --- a/flang/lib/Semantics/check-declarations.cpp +++ b/flang/lib/Semantics/check-declarations.cpp @@ -34,7 +34,6 @@ class CheckHelper { public: explicit CheckHelper(SemanticsContext &c) : context_{c} {} - CheckHelper(SemanticsContext &c, const Scope &s) : context_{c}, scope_{&s} {} SemanticsContext &context() { return context_; } void Check() { Check(context_.globalScope()); } diff --git a/flang/test/Semantics/resolve69.f90 b/flang/test/Semantics/resolve69.f90 --- a/flang/test/Semantics/resolve69.f90 +++ b/flang/test/Semantics/resolve69.f90 @@ -64,3 +64,15 @@ line%value = 'ok' Print *,Trim(line%value) End Program + +!Not errors. +subroutine outer + integer n + contains + character(n) function inner1() + inner1 = '' + end function inner1 + function inner2() + real inner2(n) + end function inner2 +end subroutine outer