File: class_79.f90

package info (click to toggle)
lfortran 0.59.0-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 56,736 kB
  • sloc: cpp: 168,052; f90: 74,272; python: 17,537; ansic: 7,705; yacc: 2,345; sh: 1,334; fortran: 895; makefile: 37; javascript: 15
file content (31 lines) | stat: -rw-r--r-- 758 bytes parent folder | download | duplicates (3)
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
module class_79_mod
  type, abstract :: class_value
    character(len=:), allocatable :: value
  end type
  type, extends(class_value) :: temp_type
    character(len=:), allocatable :: dir
    class(class_value), pointer :: cwd_ptr
  end type
  
contains 

  function cast_to_keyval(ptr) result(kval)
   class(class_value), intent(in), target :: ptr
   type(temp_type), pointer :: kval
   nullify(kval)
   select type(ptr)
    type is (temp_type)
        kval => ptr
   end select
end function cast_to_keyval
end module

program class_79
  use class_79_mod
  class(temp_type), pointer :: t
  class(class_value), allocatable :: p
  allocate(temp_type :: p)
  p%value = "Hello"
  t => cast_to_keyval(p)
  if (t%value /= "Hello") error stop
end program class_79