[flang] Handle "type(foo) function f" when foo is defined in f
authorPeter Klausler <pklausler@nvidia.com>
Sat, 5 Feb 2022 02:04:58 +0000 (18:04 -0800)
committerPeter Klausler <pklausler@nvidia.com>
Thu, 10 Feb 2022 18:29:36 +0000 (10:29 -0800)
commit93b0638eff586fabb38c18e8bb34c89661e525e5
tree9ecf8ffd6314e73f16c3103e37e6fba5965e1a05
parentbd3a1de683f80d174ea9c97000db3ec3276bc022
[flang] Handle "type(foo) function f" when foo is defined in f

Fortran allows forward references to derived types, including
function results that are typed in a prefix of a FUNCTION statement.
If a type is defined in the body of the function, a reference to
that type from a prefix on the FUNCTION statement must resolve to
the local symbol, even and especially when that type shadows one
from the host scope.

The solution is to defer the processing of that type until the
end of the function's specification part.  But the language doesn't
allow for forward references to other names in the prefix, so defer
the processing of the type only when it is not an intrinsic type.
The data structures in name resolution that track this information
for functions needed to become a stack in order to make this work,
since functions can contain interfaces that are functions.

Differential Revision: https://reviews.llvm.org/D119448
flang/lib/Evaluate/tools.cpp
flang/lib/Semantics/resolve-names.cpp
flang/test/Semantics/resolve108.f90 [new file with mode: 0644]