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