File: class_88.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 (47 lines) | stat: -rw-r--r-- 1,173 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
module class_88_m
  type t
    integer :: n = 0
   contains
    procedure :: tbp => f
  end type
 contains
  function f(this)
    class(t), pointer, intent(in) :: this
    integer, pointer :: f
    f => this%n
  end function f
end module

program test
  use class_88_m
  implicit none
  type(t), target :: xt
  class(t), pointer :: xp
  integer, pointer :: result_ptr

  ! Initialize
  xt%n = 42
  xp => xt

  ! Test type-bound procedure call with type variable
  result_ptr => xt%tbp()
  print *, result_ptr, xt%tbp()
  if (result_ptr /= 42) error stop "Failed: xt%tbp() should return 42"

  ! Test type-bound procedure call with class pointer
  result_ptr => xp%tbp()
  print *, result_ptr, xp%tbp()
  if (result_ptr /= 42) error stop "Failed: xp%tbp() should return 42"

  ! Test assignment through pointer-returning TBP with type variable
  xt%tbp() = 99
  print *, xt%tbp()
  if (xt%n /= 99) error stop "Failed: xt%tbp() = 99 should set xt%n to 99"

  ! Test assignment through pointer-returning TBP with class pointer
  xp%tbp() = 123
  print *, xp%tbp()
  if (xt%n /= 123) error stop "Failed: xp%tbp() = 123 should set xt%n to 123"

  print *, "OK"
end program test