[ORC] Merge ostream operators for SymbolStringPtrs into SymbolStringPool.h. NFC.
[llvm-project.git] / flang / test / Semantics / resolve18.f90
blob467fceb58657e3f447323efcb4919a0ebf16885b
1 ! RUN: %python %S/test_errors.py %s %flang_fc1
2 module m1
3 implicit none
4 contains
5 subroutine foo(x)
6 real :: x
7 end subroutine
8 end module
10 !Note: PGI, Intel, GNU, and NAG allow this; Sun does not
11 module 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
18 contains
19 subroutine s(i)
20 integer :: i
21 end subroutine
22 end module
24 subroutine foo
25 !ERROR: Cannot use-associate 'foo'; it is already declared in this scope
26 use m1
27 end
29 subroutine bar
30 !ERROR: Cannot use-associate 'bar'; it is already declared in this scope
31 use m1, bar => foo
32 end
34 !OK to use-associate a type with the same name as a generic
35 module m3a
36 type :: foo
37 end type
38 end
39 module m3b
40 use m3a
41 interface foo
42 end interface
43 end
45 ! Can't have derived type and function with same name
46 module m4a
47 type :: foo
48 end type
49 contains
50 !ERROR: 'foo' is already declared in this scoping unit
51 function foo(x)
52 end
53 end
54 ! Even if there is also a generic interface of that name
55 module m4b
56 type :: foo
57 end type
58 interface foo
59 procedure :: foo
60 end interface foo
61 contains
62 !ERROR: 'foo' is already declared in this scoping unit
63 function foo(x)
64 end
65 end
66 module 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
74 end
76 ! Use associating a name that is a generic and a derived type
77 module m5a
78 interface g
79 end interface
80 type g
81 end type
82 end module
83 module m5b
84 use m5a
85 interface g
86 procedure f
87 end interface
88 type(g) :: x
89 contains
90 function f(i)
91 end function
92 end module
93 subroutine s5
94 use m5b
95 type(g) :: y
96 end
98 module 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
105 end module m6
107 module 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
114 end module m7
116 module 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
123 end module m8
125 module m9
126 type f9
127 end type f9
128 interface f9
129 real function f9()
130 end function f9
131 end interface f9
132 contains
133 !ERROR: 'f9' is already declared in this scoping unit
134 function f9(x)
135 end function f9
136 end module m9
138 module m10
139 type :: t10
140 end type t10
141 interface f10
142 function f10()
143 end function f10
144 end interface f10
145 contains
146 !ERROR: 'f10' is already declared in this scoping unit
147 function f10(x)
148 end function f10
149 end module m10
151 module m11
152 type :: t11
153 end type t11
154 interface i11
155 function f11()
156 end function f11
157 end interface i11
158 contains
159 !ERROR: 'f11' is already declared in this scoping unit
160 function f11(x)
161 end function f11
162 end module m11
164 module m12
165 interface f12
166 function f12()
167 end function f12
168 end interface f12
169 contains
170 !ERROR: 'f12' is already declared in this scoping unit
171 function f12(x)
172 end function f12
173 end module m12
175 module m13
176 interface f13
177 function f13()
178 end function f13
179 end interface f13
180 contains
181 !ERROR: 'f13' is already declared in this scoping unit
182 function f13()
183 end function f13
184 end module m13
186 ! Not an error
187 module 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
196 end module m14
197 module 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
210 end module m15
212 module m15a
213 interface foo
214 module procedure foo
215 end interface
216 contains
217 function foo()
221 module m15b
222 interface foo
223 module procedure foo
224 end interface
225 contains
226 function foo(x)
230 subroutine test15
231 use m15a
232 use m15b ! ok
236 module 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)
248 module 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)
260 subroutine test16
261 use m16a
262 use m16b ! ok
265 subroutine test17
266 use m15a
267 use m16a ! ok
270 subroutine test18
271 use m16a
272 use m15a ! ok
275 module 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
288 module 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
301 module m23
302 interface foo
303 module procedure foo
304 module procedure f3
305 end interface
306 contains
307 function foo()
308 foo = 0.
310 function f3(a,b,c)
311 f3 = a + b + c
315 module m24
316 interface foo
317 module procedure foo
318 module procedure f4
319 end interface
320 contains
321 function foo(a)
322 foo = a
324 function f4(a,b,c,d)
325 f4 = a + b + c +d
329 subroutine s_21_22_a
330 use m21
331 use m22
332 print *, foo(1.) ! Intel error
333 print *, foo(1.,2.) ! Intel error
336 subroutine 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
343 subroutine 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
352 subroutine 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
361 subroutine 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