Peter Klausler 2b7a928dd9
[flang] Improve USE merging of homonymous types, interfaces, and proc… (#79364)
…edures

Fortran allows a generic interface to have the same name as a derived
type in the same scope. It also allows a generic interface to have the
same name as one of its specific procedures.

When two modules define the same name, possibly more than once each,
things get exciting. The standard is not clear, and other compilers do
variously different things. We are currently emitting some errors
prematurely for some usage in pfUnit due to how it combines two versions
of a package together via USE association.

This patch handles combinations of derived types and generic interfaces
and their specific procedures in a more principled way. Errors due to
ambiguity are deferred to actual usage of derived types and specific
procedures -- and when they're not used, the program is unambiguous and
no error issues.
2024-01-25 16:51:30 -08:00

48 lines
989 B
Fortran

! RUN: %python %S/test_symbols.py %s %flang_fc1
!DEF: /m1a Module
module m1a
!DEF: /m1a/foo PUBLIC DerivedType
type :: foo
!DEF: /m1a/foo/j ObjectEntity INTEGER(4)
integer :: j
end type
end module
!DEF: /m1b Module
module m1b
!DEF: /m1b/foo PUBLIC (Function) Generic
interface foo
!DEF: /m1b/bar PUBLIC (Function) Subprogram REAL(4)
module procedure :: bar
end interface
contains
!REF: /m1b/bar
function bar()
end function
end module
!DEF: /test1a (Subroutine) Subprogram
subroutine test1a
!REF: /m1a
use :: m1a
!REF: /m1b
use :: m1b
!DEF: /test1a/foo (Function) Generic
!DEF: /test1a/x ObjectEntity TYPE(foo)
type(foo) :: x
!REF: /m1a/foo
!REF: /m1b/bar
print *, foo(1), foo()
end subroutine
!DEF: /test1b (Subroutine) Subprogram
subroutine test1b
!REF: /m1b
use :: m1b
!REF: /m1a
use :: m1a
!DEF: /test1b/foo (Function) Generic
!DEF: /test1b/x ObjectEntity TYPE(foo)
type(foo) :: x
!REF: /m1a/foo
!REF: /m1b/bar
print *, foo(1), foo()
end subroutine