[J3] Can SOURCE and PAD argument of intrinsic RESHAPE have different declare type but the same dynamic type?

Daniel Chen cdchen at ca.ibm.com
Wed Jan 29 17:15:25 UTC 2025


Hello,

Consider the following code:
```
program main

    type Base

        integer   :: i = 88

    end type



    type, extends(Base) :: Child

        integer :: j = 99

    end type



    type(Child) :: c1(10)

    type(Child) :: c2(3,5)

    class(Base), allocatable :: b1(:)



    c1 = (/ (Child(i,i+100), i=1,10) /)

    allocate(Child::b1(2))



    c2 = reshape(c1, (/3,5/), b1, (/2,1/))   !! ERROR as c1 and b1 have different declare type.

end
```

The code is invalid as the standard requires the SOURCE and the PAD argument of intrinsic RESHAPE to have the same declare type and dynamic type. SOURCE=c1 has the declare type of Child, and PAD=b1 has the declare type of Base although they have the same dynamic type.

```
PAD (optional) shall be an array of the same type and type parameters as SOURCE.
```


It seems to me the code is not harmful. What is the reason that the standard requires both to have the same declare type?

Thanks in advance!

Daniel

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.j3-fortran.org/pipermail/j3/attachments/20250129/fdd24107/attachment.htm>


More information about the J3 mailing list