I'm working on a large project where a particular group of objects has several layers of inheritance. It's common for an object to have a method which first call's the parent object's version of that method, then performs some additional work that's specific to the child.
While this is a pattern I've followed many times, I recently discovered that if the parent class is ABSTRACT, gfortran 8.3.0 does not compiler. Here is a MWE:
MODULE typeDef
TYPE,ABSTRACT :: parent
CONTAINS
PROCEDURE :: testFoo => testFooParent
ENDTYPE parent
TYPE,EXTENDS(parent) :: child
CONTAINS
PROCEDURE :: testFoo => testFooChild
ENDTYPE child
CONTAINS
SUBROUTINE testFooParent(this)
CLASS(parent),INTENT(INOUT) :: this
WRITE(*,*) 'parent'
ENDSUBROUTINE testFooParent
SUBROUTINE testFooChild(this)
CLASS(child),INTENT(INOUT) :: this
CALL this%parent%testFoo()
WRITE(*,*) 'child'
ENDSUBROUTINE testFooChild
ENDMODULE typeDef
PROGRAM bug
ENDPROGRAM
The error I receive is here:
bug.f90:20:13:
CALL this%parent%testFoo()
1
Error: Base object for type-bound procedure call at (1) is of ABSTRACT type ‘parent’
I am aware of no such reason that this should not work, but perhaps I've missed something in the standard? If anyone can confirm for me that this is a bug before I go submit a potentially stupid bug report, that would be very helpful.
I am currently simply duplicating the parent class's behavior inside the child class's implementation. In this particular case, that's not a big deal, but it could easily cause problems down the road.