Select type selector question



Dear All,

What is a processor supposed to do with the following testcase?

implicit none

type t0
integer :: j = 42
end type t0

type, extends(t0) :: t1
integer :: k = 99
end type t1

type t
integer :: i
class(t0), allocatable :: foo
end type t

type(t) :: m(4)
integer :: n

do n = 1, 2
allocate(m(n)%foo, source = t0(n*99))
end do
do n = 3, 4
allocate(m(n)%foo, source = t1(n*99, n*999))
end do

! The class components 'foo' of m(1:2) now have a different dynamic
type to those of m(3:4)

select type(bar => m%foo) ! Should the processor throw an error here?
if not, what?
type is(t0)
if (any (bar%j .ne. [99, 198, 297, 396])) call abort
type is(t1)
call abort
end select
end

Perhaps I did not try hard enough but I was unable to find any
guidance in the standard as to what should happen. Several
possibilities come to mind:

(i) The compiler should throw the error since the ultimate components
might have different dynamic types;
(ii) A runtime check could be done, which throws an error if the
dynamic types are different;
(iii) The associate name reverts in this case to the declared type; or
............

Thanks in advance for any thoughts that you have. From tonight, the
development version of gfortran will do (i) but I would be happy to
change that if somebody can demonstrate that an alternative is
correct.

Cheers

Paul
.