On Sunday, January 24, 2021 at 1:54:02 PM UTC-5, Ev. Drikos wrote:
> Is Fortran years ahead of the competition or I've
> to file a PR for gfortran?
> ..
@Ev. Drikos,
As explained by comments in all the replies and the error message per NAG compiler, your code in the original post does not confirm to the type compatible requirements of the *intrinsic* assignment facility in the standard. The message issued by IFORT Intel Fortran compiler is as follows:
c.f90(25): error #7497: The variable must be type compatible with the expression and of the same rank. [V]
v = x
---^
compilation aborted for c.f90 (code 1)
By the way, with some of your other recent threads involving polymorphic types, are you trying to investigate gfortran and submit PR's or develop bug fixes toward outstanding bug reports?
Anyways, you will know the Fortran standard provides a facility toward *defined* assignment which can then override the intrinsic assignment to permit assignments involving types on RHS and LHS that are otherwise incompatible. Here's an example you can try if you're interested: note you can ponder over various possibilities and language support and compiler response - what if the defined assignment procedure (i.e., the equivalent of 'assign_d2-d1') has dummy arguments which are not polymorphic, or a combination thereof; what if the INTENT attribute of first dummy argument is INTENT(INOUT) versus INTENT(OUT), etc. There are several possibilities and as many or more chances of compiler implementation issues!
program test
implicit none
type :: d0
integer :: ind
end type d0
type, extends(d0) :: d1
integer :: i
end type d1
type, extends(d0) :: d2
integer :: j
end type d2
interface assignment(=)
procedure assign_d2_d1
end interface
class(d1), allocatable :: x
class(d2), allocatable :: v
allocate ( x , source = d1(1,1))
print *, "allocated x = d1(ind=1,i=1)"
allocate ( v , source = d2(2,2))
print *, "allocated v = d2(ind=2,j=2)"
v = x
print *, "assigned v = x, now v%ind=", v%ind, "j=", v%j
contains
subroutine assign_d2_d1( lhs, rhs )
class(d0), allocatable, intent(out) :: lhs
class(d0), intent(in) :: rhs
! suitable assignment actions
allocate( lhs, source=rhs ) !<-- one possible action a programmer might choose
end subroutine
end program test