It seems, that the polymorphic type information gets lost, when allocation is done with
allocate(a, mold=b)
Given the self containing example below, the code compiles, but delivers wrong results, as the wrong branch of the select type operator is executed.
Best regards, Bálint
module typedefs
implicit none
type :: Base
end type Base
type, extends(Base) :: Extended
integer :: data = -1
end type Extended
end module typedefs
program test
use typedefs
implicit none
class(Base), pointer :: ptr
type(Extended) :: myExt1
myExt1%data = 42
allocate(ptr, mold=myExt1)
select type (ptr)
type is (Extended)
print *, "This should be executed"
class default
print *, "This should NOT be executed"
end select
end program test