ICE with abstract class


the program below causes an ICE in the PGI Fortran compiler (CE, 17.10). If I comment out the “program … end program” part, then the compiler gives a message about severe errors, but finishes normally.

The thing is not that the program is syntactically incorrect, but that the compiler crashes.

I am not sure it can be reduced even further.

Kind regards,


! vectorspace.f90 --
!     Define a module for dealing with vector spaces in an abstract sense
!     The basic data type is an abstract vector, with the following
!     operations:
!     "+" - to add two vectors to get a new vector
!     "*" - to multiply a vector with a scalar
!     We can use an array of vectors as a collection: the operation ".in."
!     determines if a given vector is in that collection.
!     Note:
!     This causes an ICE in the PGI Fortran compiler
module vectorspaces
    implicit none

    type, abstract :: vector
        procedure(addition), deferred                :: add
    end type vector

    abstract interface
        function addition( a, b )
            import :: vector

            class(vector), intent(in)  :: a, b
            class(vector), allocatable :: addition
        end function addition
    end interface
end module vectorspaces

! Test this with an actual implementation
module vectors_3d
    use vectorspaces

    type, extends(vector) :: vector_3d
        real, dimension(3) :: coords
        procedure :: add       => add_3d
    end type

function add_3d( a, b )
    class(vector), intent(in)     :: a
    class(vector_3d), intent(in)  :: b
    class(vector_3d), allocatable :: add_3d

    allocate( add_3d )
    add_3d%coords = a%coords + b%coords
end function add_3d

end module vectors_3d

! Test program for the vector space modules
! Note:
!     To keep the program small, there is no facility to manipulate a collection
!     of vectors, but you could add that too.
program test_space
    use vectors_3d

    implicit none

    type(vector_3d)                :: a, b, c
    type(vector_3d), dimension(10) :: vectors

    a = vector_3d( [1.0, 1.0, 1.0] )
    b = vector_3d( [2.0, 2.0, 2.0] )
    c = a + b
end program test_space

Thanks Arjen,

It looks like that our engineers have already found and fixed this problem in PGI 18.4 which will be available shortly.

% pgf90 test.f90 -V18.4
PGF90-S-0155-Passed object dummy argument 'a' in type bound procedure 'add_3d' of type 'vector_3d' must be declared with data type 'vector_3d'  (test2.f90: 55)
PGF90-S-0155-Result is not compatible with parent's result for type bound procedure add_3d (test2.f90: 55)
PGF90-S-0099-Illegal use of operator + on a derived type (test2.f90: 73)
PGF90-S-0099-Illegal use of derived type (test2.f90: 73)
PGF90-S-0099-Illegal use of derived type (test2.f90: 73)
PGF90-S-0148-Reference to derived type required (test2.f90: 73)
  0 inform,   0 warnings,   4 severes, 0 fatal for test_space


Ah, good to know that.