File: class_103.f90

package info (click to toggle)
lfortran 0.60.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 58,412 kB
  • sloc: cpp: 173,406; f90: 80,491; python: 17,586; ansic: 9,610; yacc: 2,356; sh: 1,401; fortran: 895; makefile: 37; javascript: 15
file content (33 lines) | stat: -rw-r--r-- 797 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
! Test for https://github.com/lfortran/lfortran/issues/2925
! Typed allocation of polymorphic arrays with data members
! MRE from issue comment by difference-scheme (the data member variant)
module class_103_m

   type :: Base
      real :: data = 2.0
   end type Base

   type, extends(Base) :: Extended
   end type Extended

contains

   subroutine allocator(array)
      class(Base), allocatable, intent(out) :: array(:)
      allocate( Extended :: array(1) )
   end subroutine allocator

end module class_103_m

program class_103
   use class_103_m
   implicit none
   class(Base), allocatable :: arr(:)

   call allocator(arr)

   if (.not. allocated(arr)) error stop
   if (size(arr) /= 1) error stop
   if (abs(arr(1)%data - 2.0) > 1e-6) error stop
   print *, "PASS"
end program class_103