Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Allocatable array class components

abhimodak
New Contributor I
358 Views

Scalar allocatable class component works but array does not. Debugger does not show components of the extended type.

Perhaps this is a known issue (or am I making some mistake?)....please see the program below.

For input value of iType = 1:

When the class component is an array, I don't get the "real" component printed. The debugger shows the correct extented type picked up by the select case construct; however, the object "tree" in the debugger does not show the real component. The same is true for the scalar (variable Parcel%Object). However, the print-out does show the real component.


Abhi


=====

[fortran]
      Module OM
         
         Implicit None
         
         Type newBase
            Integer :: i = -1
         Contains
            Procedure :: Show
         End Type newBase
         
         Type, extends(newBase) :: newExtension
            Real :: r = 1.0d0
         End Type newExtension
         
      Contains
      
         Subroutine Show(OBJ)
            Class(newBase), Intent(IN) :: OBJ
            Select Type(OBJ)
               Type is (newBase)
                  Print *, OBJ%i
               Type is (newExtension)
                  Print *, OBJ%i, OBJ%r
            End Select
         End Subroutine Show
      
      End Module OM
      
      Module Shree
         Use OM
         Implicit None
         Type newWrapper
            Class(newBase), Allocatable :: Object(:)
         End Type newWrapper
         Type newCollection
            Class(newBase), Allocatable :: Object
         End Type newCollection
      End Module Shree
      
      Program Test_ClassInType
         
         Use Shree
         
         Implicit None

         Integer :: iType, ial(2)
         Type(newWrapper) :: Package
         Type(newCollection) :: Parcel
         
         Write(*,*) "Give iType: (0 or 1)"
         Read(*,*) iType
         
         Select Case(iType)
            Case(0)
               Allocate(newBase :: Package%Object(2), stat=ial(1))
               Allocate(newBase :: Parcel%Object, stat=ial(2))
            Case(1)
               Allocate(newExtension :: Package%Object(2), stat=ial(1))
               Allocate(newExtension :: Parcel%Object, stat=ial(2)) 
            Case Default
               Write(*,*) "Invalid."
         End Select
         
         Write(*,"(A,I0)") "ial(1)=", ial(1)
         Write(*,"(A,I0)") "ial(2)=", ial(2)
         
         Write(*,*)
         Write(*,*) "Showing Package%Object(1)"
         Call Package%Object(1)%Show()
         
         Write(*,*)         
         Write(*,*) "Showing Parcel%Object"
         Call Parcel%Object%Show()

      End Program Test_ClassInType
[/fortran]

0 Kudos
4 Replies
Steven_L_Intel1
Employee
358 Views
Is the issue that the debugger doesn't show the right value, but the program works anyway? Debugger support for polymorphic types has some issues we are working on.
0 Kudos
abhimodak
New Contributor I
358 Views
Hi Steve

The problem is with both: (a) program does not work as expected, (b) debugger does not show correct information.

(a) More specifically, for iType == 1, Package%Obejct should be an array of extended type. However, this does not seem to happen. Whereas Parcel%Object is correctly becomes a variable of extended type. The write statement prints only integer component for Package%Object(1) while both, real and integer, components are printed for Parcel%Object.

(b) I am aware of issues related to the debugger; although this one also falls unders same category, I think, it is happening in a "new" place.

Abhi
0 Kudos
Steven_L_Intel1
Employee
358 Views
Ok, thanks. I can reproduce both issues. I have escalated this as DPD200161615.
0 Kudos
Steven_L_Intel1
Employee
358 Views
The program not working was fixed in 12.0 Update 2.
0 Kudos
Reply