1! RUN: %S/test_errors.sh %s %t %flang_fc1
2! REQUIRES: shell
3! Extended derived types
4
5module m1
6  type :: t1
7    integer :: x
8    !ERROR: Component 'x' is already declared in this derived type
9    real :: x
10  end type
11end
12
13module m2
14  type :: t1
15    integer :: i
16  end type
17  type, extends(t1) :: t2
18    !ERROR: Component 'i' is already declared in a parent of this derived type
19    integer :: i
20  end type
21end
22
23module m3
24  type :: t1
25  end type
26  type, extends(t1) :: t2
27    integer :: i
28    !ERROR: 't1' is a parent type of this type and so cannot be a component
29    real :: t1
30  end type
31  type :: t3
32  end type
33  type, extends(t3) :: t4
34  end type
35  type, extends(t4) :: t5
36    !ERROR: 't3' is a parent type of this type and so cannot be a component
37    real :: t3
38  end type
39end
40
41module m4
42  type :: t1
43    integer :: t1
44  end type
45  !ERROR: Type cannot be extended as it has a component named 't1'
46  type, extends(t1) :: t2
47  end type
48end
49
50module m5
51  type :: t1
52    integer :: t2
53  end type
54  type, extends(t1) :: t2
55  end type
56  !ERROR: Type cannot be extended as it has a component named 't2'
57  type, extends(t2) :: t3
58  end type
59end
60
61module m6
62  ! t1 can be extended if it is known as anything but t3
63  type :: t1
64    integer :: t3
65  end type
66  type, extends(t1) :: t2
67  end type
68end
69subroutine s6
70  use :: m6, only: t3 => t1
71  !ERROR: Type cannot be extended as it has a component named 't3'
72  type, extends(t3) :: t4
73  end type
74end
75subroutine r6
76  use :: m6, only: t5 => t1
77  type, extends(t5) :: t6
78  end type
79end
80
81module m7
82  type, private :: t1
83    integer :: i1
84  end type
85  type, extends(t1) :: t2
86    integer :: i2
87    integer, private :: i3
88  end type
89end
90subroutine s7
91  use m7
92  type(t2) :: x
93  integer :: j
94  j = x%i2
95  !ERROR: PRIVATE component 'i3' is only accessible within module 'm7'
96  j = x%i3
97  !ERROR: PRIVATE component 't1' is only accessible within module 'm7'
98  j = x%t1%i1
99end
100
101! 7.5.4.8(2)
102module m8
103  type  :: t
104    integer :: i1
105    integer, private :: i2
106  end type
107  type(t) :: y
108  integer :: a(1)
109contains
110  subroutine s0
111    type(t) :: x
112    x = t(i1=2, i2=5)  !OK
113  end
114  subroutine s1
115    a = [y%i2]  !OK
116  end subroutine
117end
118subroutine s8
119  use m8
120  type(t) :: x
121  !ERROR: PRIVATE component 'i2' is only accessible within module 'm8'
122  x = t(2, 5)
123  !ERROR: PRIVATE component 'i2' is only accessible within module 'm8'
124  x = t(i1=2, i2=5)
125  !ERROR: PRIVATE component 'i2' is only accessible within module 'm8'
126  a = [y%i2]
127end
128
129! 7.5.4.8(2)
130module m9
131  interface
132    module subroutine s()
133    end subroutine
134  end interface
135  type  :: t
136    integer :: i1
137    integer, private :: i2
138  end type
139end
140submodule(m9) sm8
141contains
142  module subroutine s
143    type(t) :: x
144    x = t(i1=2, i2=5)  !OK
145  end
146end
147