(j3.2006) Parent component of extension of abstract type

Damian Rouson damian
Thu Nov 12 19:32:04 EST 2015

> On Nov 12, 2015, at 1:32 PM, Van Snyder <Van.Snyder at jpl.nasa.gov> wrote:
> It seems a bit strange that I can't access the parent component of an
> object of a type that is an extension of an abstract type, but I can
> access components of the parent component.  Is this what we intended?
> program P
>  type, abstract :: T0
>    integer :: N = 42
>  end type T0
>  type, extends(t0) :: T1
>  end type T1
>  type(t1) :: V1, V2
>  print '(a,i0)', 'V1 ', v1
>  print '(a,i0)', 'V1%T0 ', v1%t0      ! Prohibited
>  print '(a,i0)', 'V1%T0%n ', v1%t0%n
>  v2 = v1
>  v2%t0 = v1%t0                        ! Prohibited
>  v2%t0%n = v1%t0%n

Where is or are the relevant prohibition(s)?  The Cray, Portland Group, and GNU Fortran compilers all accept the above code and the resulting executable terminates without error:

$ gfortran van.f90 
$ ./a.out
V1 42
V1%T0 42
V1%T0%n 42

Are the aforementioned compilers accepting non-conforming code?  I haven?t tried other compilers.

On a peripherally related note, I?m surprised that I didn?t know you could print an object of derived type without derived type I/O, but I guess that?s because the one rule of OOP that I adhere to most strongly is data privacy.   The first print statement in the above code wouldn?t work if the types were encapsulated in a module and given the private attribute.  This makes me really wish we the list-directed version of the first print statement were allowed with private components:

print *, 'V1 ?,v1

If the list-directed version worked when type T1 is defined in a module and has private components, it would eliminate a lot of my need for derived type I/O.  I hope that allowing this can be considered in a future standard.  The list-directed print statement exploits no information about the components.  Of course, the statement?s behavior could change if the type?s definition changes, but that?s also true for derived type I/O so it feels like an artificial restriction.


More information about the J3 mailing list