xref: /llvm-project/flang/test/Semantics/resolve18.f90 (revision 2b7a928dd97476aac86fbae25a7a8e26b4ced738)
1! RUN: %python %S/test_errors.py %s %flang_fc1
2module m1
3  implicit none
4contains
5  subroutine foo(x)
6    real :: x
7  end subroutine
8end module
9
10!Note: PGI, Intel, GNU, and NAG allow this; Sun does not
11module m2
12  use m1
13  implicit none
14  !WARNING: 'foo' should not be the name of both a generic interface and a procedure unless it is a specific procedure of the generic
15  interface foo
16    module procedure s
17  end interface
18contains
19  subroutine s(i)
20    integer :: i
21  end subroutine
22end module
23
24subroutine foo
25  !ERROR: Cannot use-associate 'foo'; it is already declared in this scope
26  use m1
27end
28
29subroutine bar
30  !ERROR: Cannot use-associate 'bar'; it is already declared in this scope
31  use m1, bar => foo
32end
33
34!OK to use-associate a type with the same name as a generic
35module m3a
36  type :: foo
37  end type
38end
39module m3b
40  use m3a
41  interface foo
42  end interface
43end
44
45! Can't have derived type and function with same name
46module m4a
47  type :: foo
48  end type
49contains
50  !ERROR: 'foo' is already declared in this scoping unit
51  function foo(x)
52  end
53end
54! Even if there is also a generic interface of that name
55module m4b
56  type :: foo
57  end type
58  interface foo
59    procedure :: foo
60  end interface foo
61contains
62  !ERROR: 'foo' is already declared in this scoping unit
63  function foo(x)
64  end
65end
66module m4c
67  type :: foo
68  end type
69  interface foo
70    !ERROR: 'foo' is already declared in this scoping unit
71    real function foo()
72    end function foo
73  end interface foo
74end
75
76! Use associating a name that is a generic and a derived type
77module m5a
78  interface g
79  end interface
80  type g
81  end type
82end module
83module m5b
84  use m5a
85  interface g
86    procedure f
87  end interface
88  type(g) :: x
89contains
90  function f(i)
91  end function
92end module
93subroutine s5
94  use m5b
95  type(g) :: y
96end
97
98module m6
99  real :: f6
100  interface g6
101  !ERROR: 'f6' is already declared in this scoping unit
102    real function f6()
103    end function f6
104  end interface g6
105end module m6
106
107module m7
108  integer :: f7
109  interface g7
110    !ERROR: 'f7' is already declared in this scoping unit
111    real function f7()
112    end function f7
113  end interface g7
114end module m7
115
116module m8
117  real :: f8
118  interface g8
119    !ERROR: 'f8' is already declared in this scoping unit
120    subroutine f8()
121    end subroutine f8
122  end interface g8
123end module m8
124
125module m9
126  type f9
127  end type f9
128  interface f9
129    real function f9()
130    end function f9
131  end interface f9
132contains
133  !ERROR: 'f9' is already declared in this scoping unit
134  function f9(x)
135  end function f9
136end module m9
137
138module m10
139  type :: t10
140  end type t10
141  interface f10
142    function f10()
143    end function f10
144  end interface f10
145contains
146  !ERROR: 'f10' is already declared in this scoping unit
147  function f10(x)
148  end function f10
149end module m10
150
151module m11
152  type :: t11
153  end type t11
154  interface i11
155    function f11()
156    end function f11
157  end interface i11
158contains
159  !ERROR: 'f11' is already declared in this scoping unit
160  function f11(x)
161  end function f11
162end module m11
163
164module m12
165  interface f12
166    function f12()
167    end function f12
168  end interface f12
169contains
170  !ERROR: 'f12' is already declared in this scoping unit
171  function f12(x)
172  end function f12
173end module m12
174
175module m13
176  interface f13
177    function f13()
178    end function f13
179  end interface f13
180contains
181  !ERROR: 'f13' is already declared in this scoping unit
182  function f13()
183  end function f13
184end module m13
185
186! Not an error
187module m14
188  interface gen1
189    module procedure s
190  end interface
191  generic :: gen2 => s
192 contains
193  subroutine s(x)
194    integer(1) :: x
195  end subroutine s
196end module m14
197module m15
198  use m14
199  interface gen1
200    module procedure gen1
201  end interface
202  generic :: gen2 => gen2
203 contains
204  subroutine gen1(x)
205    integer(2) :: x
206  end subroutine gen1
207  subroutine gen2(x)
208    integer(4) :: x
209  end subroutine gen2
210end module m15
211
212module m15a
213  interface foo
214    module procedure foo
215  end interface
216 contains
217  function foo()
218  end
219end
220
221module m15b
222  interface foo
223    module procedure foo
224  end interface
225 contains
226  function foo(x)
227  end
228end
229
230subroutine test15
231  use m15a
232  use m15b ! ok
233end
234
235
236module m16a
237  type foo
238    integer j
239  end type
240  interface foo
241    module procedure bar
242  end interface
243 contains
244  function bar(j)
245  end
246end
247
248module m16b
249  type foo
250    integer j, k
251  end type
252  interface foo
253    module procedure bar
254  end interface
255 contains
256  function bar(x,y)
257  end
258end
259
260subroutine test16
261  use m16a
262  use m16b ! ok
263end
264
265subroutine test17
266  use m15a
267  use m16a ! ok
268end
269
270subroutine test18
271  use m16a
272  use m15a ! ok
273end
274
275module m21
276  type foo
277    integer a
278  end type
279  interface foo
280    module procedure f1
281  end interface
282 contains
283  function f1(a)
284    f1 = a
285  end
286end
287
288module m22
289  type foo
290    real b
291  end type
292  interface foo
293    module procedure f2
294  end interface
295 contains
296  function f2(a,b)
297    f2 = a + b
298  end
299end
300
301module m23
302  interface foo
303    module procedure foo
304    module procedure f3
305  end interface
306 contains
307  function foo()
308    foo = 0.
309  end
310  function f3(a,b,c)
311    f3 = a + b + c
312  end
313end
314
315module m24
316  interface foo
317    module procedure foo
318    module procedure f4
319  end interface
320 contains
321  function foo(a)
322    foo = a
323  end
324  function f4(a,b,c,d)
325    f4 = a + b + c +d
326  end
327end
328
329subroutine s_21_22_a
330  use m21
331  use m22
332  print *, foo(1.) ! Intel error
333  print *, foo(1.,2.) ! Intel error
334end
335
336subroutine s_21_22_b
337  use m21
338  use m22
339  !ERROR: 'foo' is not a derived type
340  type(foo) x ! definite error: GNU and Intel catch
341end
342
343subroutine s_21_23
344  use m21
345  use m23
346  type(foo) x ! Intel and NAG error
347  print *, foo(1.) ! Intel error
348  print *, foo(1.,2.,3.) ! Intel error
349  call ext(foo) ! GNU and Intel error
350end
351
352subroutine s_22_23
353  use m22
354  use m23
355  type(foo) x ! Intel and NAG error
356  print *, foo(1.,2.) ! Intel error
357  print *, foo(1.,2.,3.) ! Intel error
358  call ext(foo) ! Intel error
359end
360
361subroutine s_23_24
362  use m23
363  use m24
364  print *, foo(1.,2.,3.) ! NAG error
365  print *, foo(1.,2.,3.,4.) ! XLF error
366  !ERROR: 'foo' is not a specific procedure
367  call ext(foo) ! definite error
368end
369