I have another issue with my code, and I’d like to know if I’m being sloppy with the Fortran 2003 Standard or if it’s yet another problem of the PGI compiler. In some situations the code compiles successfully, but other times it doesn’t. The issue doesn’t show up with other compilers. So, consider the following program (a highly truncated version of mine),
MODULE scalars IMPLICIT NONE PRIVATE PUBLIC :: scalar TYPE :: scalar COMPLEX :: idx CONTAINS PRIVATE PROCEDURE, PASS :: eq_sca GENERIC, PUBLIC :: ASSIGNMENT(=) => eq_sca END TYPE scalar INTERFACE scalar MODULE PROCEDURE ctor_sca END INTERFACE scalar CONTAINS PURE ELEMENTAL FUNCTION ctor_sca(z) RESULT(u) COMPLEX, INTENT(in) :: z TYPE(scalar) :: u u%idx = z END FUNCTION ctor_sca PURE ELEMENTAL SUBROUTINE eq_sca(u, v) CLASS(scalar), INTENT(out) :: u CLASS(scalar), INTENT(in) :: v ! <==  !TYPE(scalar), INTENT(in) :: v ! <==  u%idx = v%idx END SUBROUTINE eq_sca END MODULE scalars PROGRAM test USE scalars IMPLICIT NONE TYPE(scalar) :: a COMPLEX :: z z = (0.,1.) a = scalar(z) ! <==  PRINT *, "scalar =", a END PROGRAM test
The module contains a derived data type with a single COMPLEX component, called “scalar”, its structure constructor, and a type-bound overloaded assignment. If I try to compile it, the compiler returns the following error message:
PGF90-S-0000-Internal compiler error. select_rtemp: bad ili 0 (test.f90: 49)
PGF90-S-0000-Internal compiler error. exp_call: ili ret type not cased 22 (test.f90: 49)
0 inform, 0 warnings, 2 severes, 0 fatal for test
The problem is in the interpretation of the type-bound assignment in line . If I use line  as above, the compilation fails, but if I use TYPE instead of CLASS (line ) then the compilation is successful and the program runs normally.
The same error shows up if I promote the component “idx” to an array of odd rank, for example
COMPLEX :: idx(5) COMPLEX :: idx(5:5:5) COMPLEX :: idx(5:5:5:5:5) ...
If the rank is even, however, the compilation is successful and the program runs without problems, even if both dummy arguments in the assignment procedure “eq_sca” have the CLASS attribute.
So, is this another bug of the compiler, or are the CLASS attributes in the overloaded assignment an abuse of the Fortran 2003 language? I thought this could be the case, but it works in the even-rank cases with the PGI compiler, and in all cases with other compilers.
NOTE: The same issue occurs if I use a public overloaded assignment that is not type bound.