I'd like to know if it is legal to pass an object which is defined as class (A) :: Ainst to a subroutine which actually expects a type(A). Is that covered by the F2003 standard?
It seems to work as the code below works on IVF 11.1.038. Clearly, I won't have access to the fields unique to B, but I don't mind that.
The main reason why I'd like to know whether this is valid is twofold. First of all, currently, class objects are not correctly displayed in the debugger (I submitted that before). If I'd like to use member functions, I am forced to use class objects instead of types, therefore I cannot debug in member functions. Using a wrapper as a member function which in turn uses type instead of class would allow us to bypass this problem until it is solved.
Furthermore, performance test I haveperformed indicate, that there is some penalty for using a class reference instead of a type reference. With the wrapper function workaround, this penalty disappeared.
I think a"cleaner" approach would be to use a select type statement and put the call to a TYPE IS ... section, however, my performance test showed that this does add measureable overhead (actually much more than I expected, makes my simple test of adding large arrays about 6 times slower!).
module TypeDefs implicit none type :: A integer :: val contains procedure Display end type type, extends(A) :: B integer :: val2 end type contains subroutine Display( this ) class (A) :: this CALL DisplayA( this ) end subroutine subroutine DisplayA( this ) type (A) :: this write (*,*) 'DisplayA: ', this%val end subroutine end module TypeDefs program Test use TypeDefs type (B), target :: Binst Binst%val = 1 Binst%val2 = 2 CALL Binst%Display end program Test