1! RUN: %S/test_errors.sh %s %t %flang_fc1
2! REQUIRES: shell
3module m
4  integer :: foo
5  !Note: PGI, Intel, and GNU allow this; NAG and Sun do not
6  !ERROR: 'foo' is already declared in this scoping unit
7  interface foo
8  end interface
9end module
10
11module m2
12  interface s
13  end interface
14contains
15  !ERROR: 's' may not be the name of both a generic interface and a procedure unless it is a specific procedure of the generic
16  subroutine s
17  end subroutine
18end module
19
20module m3
21  ! This is okay: s is generic and specific
22  interface s
23    procedure s2
24  end interface
25  interface s
26    procedure s
27  end interface
28contains
29  subroutine s()
30  end subroutine
31  subroutine s2(x)
32  end subroutine
33end module
34
35module m4a
36  interface g
37    procedure s_real
38  end interface
39contains
40  subroutine s_real(x)
41  end
42end
43module m4b
44  interface g
45    procedure s_int
46  end interface
47contains
48  subroutine s_int(i)
49  end
50end
51! Generic g should merge the two use-associated ones
52subroutine s4
53  use m4a
54  use m4b
55  call g(123)
56  call g(1.2)
57end
58
59module m5a
60  interface g
61    procedure s_real
62  end interface
63contains
64  subroutine s_real(x)
65  end
66end
67module m5b
68  interface gg
69    procedure s_int
70  end interface
71contains
72  subroutine s_int(i)
73  end
74end
75! Generic g should merge the two use-associated ones
76subroutine s5
77  use m5a
78  use m5b, g => gg
79  call g(123)
80  call g(1.2)
81end
82
83module m6a
84  interface gg
85    procedure sa
86  end interface
87contains
88  subroutine sa(x)
89  end
90end
91module m6b
92  interface gg
93    procedure sb
94  end interface
95contains
96  subroutine sb(y)
97  end
98end
99subroutine s6
100  !ERROR: Generic 'g' may not have specific procedures 'sa' and 'sb' as their interfaces are not distinguishable
101  use m6a, g => gg
102  use m6b, g => gg
103end
104
105module m7a
106  interface g
107    procedure s1
108  end interface
109contains
110  subroutine s1(x)
111  end
112end
113module m7b
114  interface g
115    procedure s2
116  end interface
117contains
118  subroutine s2(x, y)
119  end
120end
121module m7c
122  interface g
123    procedure s3
124  end interface
125contains
126  subroutine s3(x, y, z)
127  end
128end
129! Merge the three use-associated generics
130subroutine s7
131  use m7a
132  use m7b
133  use m7c
134  call g(1.0)
135  call g(1.0, 2.0)
136  call g(1.0, 2.0, 3.0)
137end
138
139module m8a
140  interface g
141    procedure s1
142  end interface
143contains
144  subroutine s1(x)
145  end
146end
147module m8b
148  interface g
149    procedure s2
150  end interface
151contains
152  subroutine s2(x, y)
153  end
154end
155module m8c
156  integer :: g
157end
158! If merged generic conflicts with another USE, it is an error (if it is referenced)
159subroutine s8
160  use m8a
161  use m8b
162  use m8c
163  !ERROR: Reference to 'g' is ambiguous
164  g = 1
165end
166
167module m9a
168  interface g
169    module procedure g
170  end interface
171contains
172  subroutine g()
173  end
174end module
175module m9b
176  interface g
177    module procedure g
178  end interface
179contains
180  subroutine g(x)
181    real :: x
182  end
183end module
184module m9c
185  interface g
186    module procedure g
187  end interface
188contains
189  subroutine g()
190  end
191end module
192subroutine s9a
193  use m9a
194  use m9b
195end
196subroutine s9b
197  !ERROR: USE-associated generic 'g' may not have specific procedures 'g' and 'g' as their interfaces are not distinguishable
198  use m9a
199  use m9c
200end
201
202module m10a
203  interface g
204    module procedure s
205  end interface
206  private :: s
207contains
208  subroutine s(x)
209    integer :: x
210  end
211end
212module m10b
213  use m10a
214  !ERROR: Generic 'g' may not have specific procedures 's' and 's' as their interfaces are not distinguishable
215  interface g
216    module procedure s
217  end interface
218  private :: s
219contains
220  subroutine s(x)
221    integer :: x
222  end
223end
224
225module m11a
226  interface g
227  end interface
228  type g
229  end type
230end module
231module m11b
232  interface g
233  end interface
234  type g
235  end type
236end module
237module m11c
238  use m11a
239  !ERROR: Generic interface 'g' has ambiguous derived types from modules 'm11a' and 'm11b'
240  use m11b
241end module
242
243module m12a
244  interface ga
245    module procedure sa
246  end interface
247contains
248  subroutine sa(i)
249  end
250end
251module m12b
252  use m12a
253  interface gb
254    module procedure sb
255  end interface
256contains
257  subroutine sb(x)
258  end
259end
260module m12c
261  use m12b, only: gc => gb
262end
263module m12d
264  use m12a, only: g => ga
265  use m12c, only: g => gc
266  interface g
267  end interface
268end module
269