This is an archive of the discontinued LLVM Phabricator instance.

[flang] Handle "type(foo) function f" when foo is defined in f
ClosedPublic

Authored by klausler on Feb 10 2022, 8:45 AM.

Details

Summary

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.

Diff Detail

Event Timeline

klausler created this revision.Feb 10 2022, 8:45 AM
klausler requested review of this revision.Feb 10 2022, 8:45 AM
PeteSteinfeld accepted this revision.Feb 10 2022, 9:51 AM

This is a weird corner of the language.

All build and tests correctly and looks good.

This revision is now accepted and ready to land.Feb 10 2022, 9:51 AM
This revision was landed with ongoing or failed builds.Feb 10 2022, 10:29 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptFeb 10 2022, 10:29 AM