summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gfortran.dg/unlimited_polymorphic_26.f90
blob: c3b42216ffd3119ce691e65edcc77e404b8e8a3b (plain)
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
! { dg-do run }
!
! Test contributed by Valery Weber  <valeryweber@hotmail.com>

module mod

  TYPE, PUBLIC :: dict_entry_type
     CLASS( * ), ALLOCATABLE :: key
     CLASS( * ), ALLOCATABLE :: val
  END TYPE dict_entry_type


contains

  SUBROUTINE dict_put ( this, key, val )
    CLASS(dict_entry_type), INTENT(INOUT)     :: this
    CLASS(*), INTENT(IN)                     :: key, val
    INTEGER                                  :: istat
    ALLOCATE( this%key, SOURCE=key, STAT=istat )
    ALLOCATE( this%val, SOURCE=val, STAT=istat )
  end SUBROUTINE dict_put
end module mod

program test
  use mod
  type(dict_entry_type) :: t
  call dict_put(t, "foo", 42)

  if (.NOT. allocated(t%key)) STOP 1
  select type (x => t%key)
    type is (CHARACTER(*))
      if (x /= "foo") STOP 2
    class default
      STOP 3
  end select
  deallocate(t%key)

  if (.NOT. allocated(t%val)) STOP 4
  select type (x => t%val)
    type is (INTEGER)
      if (x /= 42) STOP 5
    class default
      STOP 6
  end select
  deallocate(t%val)
end