1! RUN: %B/test/Semantics/test_errors.sh %s %flang %t
2module m
3  integer :: foo
4  !Note: PGI, Intel, and GNU allow this; NAG and Sun do not
5  !ERROR: 'foo' is already declared in this scoping unit
6  interface foo
7  end interface
8end module
9
10module m2
11  interface s
12  end interface
13contains
14  !ERROR: 's' may not be the name of both a generic interface and a procedure unless it is a specific procedure of the generic
15  subroutine s
16  end subroutine
17end module
18
19module m3
20  ! This is okay: s is generic and specific
21  interface s
22    procedure s2
23  end interface
24  interface s
25    procedure s
26  end interface
27contains
28  subroutine s()
29  end subroutine
30  subroutine s2(x)
31  end subroutine
32end module
33
34module m4a
35  interface g
36    procedure s_real
37  end interface
38contains
39  subroutine s_real(x)
40  end
41end
42module m4b
43  interface g
44    procedure s_int
45  end interface
46contains
47  subroutine s_int(i)
48  end
49end
50! Generic g should merge the two use-associated ones
51subroutine s4
52  use m4a
53  use m4b
54  call g(123)
55  call g(1.2)
56end
57
58module m5a
59  interface g
60    procedure s_real
61  end interface
62contains
63  subroutine s_real(x)
64  end
65end
66module m5b
67  interface gg
68    procedure s_int
69  end interface
70contains
71  subroutine s_int(i)
72  end
73end
74! Generic g should merge the two use-associated ones
75subroutine s5
76  use m5a
77  use m5b, g => gg
78  call g(123)
79  call g(1.2)
80end
81
82module m6a
83  interface gg
84    procedure sa
85  end interface
86contains
87  subroutine sa(x)
88  end
89end
90module m6b
91  interface gg
92    procedure sb
93  end interface
94contains
95  subroutine sb(y)
96  end
97end
98subroutine s6
99  !ERROR: Generic 'g' may not have specific procedures 'sa' and 'sb' as their interfaces are not distinguishable
100  use m6a, g => gg
101  use m6b, g => gg
102end
103
104module m7a
105  interface g
106    procedure s1
107  end interface
108contains
109  subroutine s1(x)
110  end
111end
112module m7b
113  interface g
114    procedure s2
115  end interface
116contains
117  subroutine s2(x, y)
118  end
119end
120module m7c
121  interface g
122    procedure s3
123  end interface
124contains
125  subroutine s3(x, y, z)
126  end
127end
128! Merge the three use-associated generics
129subroutine s7
130  use m7a
131  use m7b
132  use m7c
133  call g(1.0)
134  call g(1.0, 2.0)
135  call g(1.0, 2.0, 3.0)
136end
137
138module m8a
139  interface g
140    procedure s1
141  end interface
142contains
143  subroutine s1(x)
144  end
145end
146module m8b
147  interface g
148    procedure s2
149  end interface
150contains
151  subroutine s2(x, y)
152  end
153end
154module m8c
155  integer :: g
156end
157! If merged generic conflicts with another USE, it is an error (if it is referenced)
158subroutine s8
159  use m8a
160  use m8b
161  use m8c
162  !ERROR: Reference to 'g' is ambiguous
163  g = 1
164end
165
166module m9a
167  interface g
168    module procedure s1
169    module procedure g
170  end interface
171contains
172  subroutine g()
173  end
174  subroutine s1(x)
175    integer :: x
176  end
177end module
178module m9b
179  use m9a
180  interface g
181    module procedure s2
182  end interface
183contains
184  subroutine s2(x)
185    real :: x
186  end
187end module
188module m9c
189  interface g
190    module procedure g
191  end interface
192contains
193  subroutine g(x)
194    real :: x
195  end
196end module
197! Merge use-associated generics that have the same symbol (s1)
198subroutine s9
199  use m9a
200  use m9b
201end
202! Merge use-associate generics each with specific of same name
203subroutine s9c
204  use m9a
205  !ERROR: Generic interface 'g' has ambiguous specific procedures from modules 'm9a' and 'm9c'
206  use m9c
207end
208