You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[flang] Better error handling and testing of generics with homonymous specifics or derived types
Fortran allows a generic procedure interface to have the same name as a derived
type in the same scope or the same name as one of its specific procedures.
(It can't have both since a derived type and specific procedure can't have the
same name in a scope.)
Some popular compilers allow generic interfaces with distinct accessible homonymous
specific procedures to be merged by USE association. Thsi compiler does not,
and for good reason: it leads to ambiguity in cases where a procedure name appears
outside a reference, such as in a PROCEDURE declaration statement as the procedure's
interface, the target of a procedure pointer assignment statement, or as an
actual argument.
This patch cleans up the code that handles these cases, improves some error
messages, and adds more tests.
Resolvesllvm#60228.
Differential Revision: https://reviews.llvm.org/D150915
"Cannot use-associate generic interface '%s' with specific procedure of the same name when another such interface and derived type are in scope"_err_en_US;
"Cannot use-associate generic interface '%s' with specific procedure of the same name when another such generic is in scope"_err_en_US,
3023
-
localName)
3024
-
.Attach(
3025
-
localSymbol.name(), "Previous USE of '%s'"_en_US, localName);
3024
+
&useSpec->GetUltimate()) {
3025
+
msg =
3026
+
"Cannot use-associate generic interface '%s' with specific procedure of the same name when another such interface and procedure are in scope"_err_en_US;
3027
+
}
3028
+
} elseif (const Symbol * useDT{useGeneric->derivedType()};
3029
+
useDT && !useDT->attrs().test(Attr::PRIVATE)) {
3030
+
if (localGeneric->specific()) {
3031
+
msg =
3032
+
"Cannot use-associate generic interface '%s' with derived type of the same name when another such interface and procedure are in scope"_err_en_US;
Copy file name to clipboardExpand all lines: flang/test/Semantics/resolve18.f90
+68-2Lines changed: 68 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -55,11 +55,11 @@ function foo(x)
55
55
module m4b
56
56
type :: foo
57
57
end type
58
-
!ERROR: 'foo' is already declared in this scoping unit
59
58
interfacefoo
60
59
procedure:: foo
61
60
endinterface foo
62
61
contains
62
+
!ERROR: 'foo' is already declared in this scoping unit
63
63
functionfoo(x)
64
64
end
65
65
end
@@ -125,12 +125,12 @@ end module m8
125
125
module m9
126
126
typef9
127
127
endtype f9
128
-
!ERROR: 'f9' is already declared in this scoping unit
129
128
interfacef9
130
129
realfunctionf9()
131
130
endfunction f9
132
131
endinterface f9
133
132
contains
133
+
!ERROR: 'f9' is already declared in this scoping unit
134
134
functionf9(x)
135
135
endfunction f9
136
136
end module m9
@@ -208,3 +208,69 @@ subroutine gen2(x)
208
208
integer(4) :: x
209
209
endsubroutine gen2
210
210
end module m15
211
+
212
+
module m15a
213
+
interfacefoo
214
+
moduleprocedure foo
215
+
endinterface
216
+
contains
217
+
functionfoo()
218
+
end
219
+
end
220
+
221
+
module m15b
222
+
interfacefoo
223
+
moduleprocedure foo
224
+
endinterface
225
+
contains
226
+
functionfoo(x)
227
+
end
228
+
end
229
+
230
+
subroutinetest15
231
+
use m15a
232
+
!ERROR: Cannot use-associate generic interface 'foo' with specific procedure of the same name when another such interface and procedure are in scope
233
+
use m15b
234
+
end
235
+
236
+
module m16a
237
+
typefoo
238
+
integer j
239
+
endtype
240
+
interfacefoo
241
+
moduleprocedure bar
242
+
endinterface
243
+
contains
244
+
functionbar(j)
245
+
end
246
+
end
247
+
248
+
module m16b
249
+
typefoo
250
+
integer j, k
251
+
endtype
252
+
interfacefoo
253
+
moduleprocedure bar
254
+
endinterface
255
+
contains
256
+
functionbar(x,y)
257
+
end
258
+
end
259
+
260
+
subroutinetest16
261
+
use m16a
262
+
!ERROR: Generic interface 'foo' has ambiguous derived types from modules 'm16a' and 'm16b'
263
+
use m16b
264
+
end
265
+
266
+
subroutinetest17
267
+
use m15a
268
+
!ERROR: Cannot use-associate generic interface 'foo' with derived type of the same name when another such interface and procedure are in scope
269
+
use m16a
270
+
end
271
+
272
+
subroutinetest18
273
+
use m16a
274
+
!ERROR: Cannot use-associate generic interface 'foo' with specific procedure of the same name when another such interface and derived type are in scope
0 commit comments