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

Clune, Thomas L. (GSFC-6101) thomas.l.clune at nasa.gov
Wed Jan 29 17:22:11 UTC 2025


Hi Daniel,

In your case the compiler could in theory “figure out” that b1 is of the same type as c1.   But consider if b1 were instead a CLASS(Base) dummy argument.     It might then have a different dynamic type, in which case it would not make sense as a PAD.    We want this to be caught at compile time rather than run time.


  *   Tom

From: J3 <j3-bounces at mailman.j3-fortran.org> on behalf of Daniel Chen via J3 <j3 at mailman.j3-fortran.org>
Date: Wednesday, January 29, 2025 at 12:16 PM
To: Van Snyder via J3 <j3 at mailman.j3-fortran.org>
Cc: Daniel Chen <cdchen at ca.ibm.com>
Subject: [EXTERNAL] [BULK] [J3] Can SOURCE and PAD argument of intrinsic RESHAPE have different declare type but the same dynamic type?
CAUTION: This email originated from outside of NASA.  Please take care when clicking links or opening attachments.  Use the "Report Message" button to report suspicious messages to the NASA SOC.



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/5ab70792/attachment-0001.htm>


More information about the J3 mailing list