As seen in some previous post happen sometimes the desire to go beyond the TKR restriction. I don’t know if something similar has been already proposed.
As I have already written in another post (I repeat here for clarity) I suggest to introduce another syntax element. Let’s call it generic_case
. I’m not yet giving a formal specification at this moment.
generic_case <generic_case_name>
module procedure <procedure name 1>
module procedure <procedure name 2>
case <generic case name 1>
...
end generic_case
The <generic_case_name>
is not a generic name as intended in Fortran, it is more like a symbol. If defined in a used module (and made accessible in the using module) it cannot be redefined.
It can include other <generic case names>
. A procedure can appear more then one time
inside a generic_case statement. The procedure shouldn’t be TKR distinguishable.
If a routine is called by the generic_case name the first TKR compatible procedure will be the actual procedure that will be called. If inside a generic_case
statement another generic_case name is referenced the last will be searched in sequence in order to find a procedure that match.
A generic-case statement
create a generic-case-list
with all the procedures that appear directly or indirectly inside that generic-case
.
As a generic_case name is not a generic name
as intended in Fortran you cannot change the behaviour of an already compiled module.
Now, a generic_case
name cannot be an operator (of course). So one have to introduce a change on the interface statement, and now the TKR distinguishability kick in again.
The change will be:
interface-specification is interface-body or procedure-stmt or generic-case-name-stmt
generic-case-name-stmt is CASE generic-case-name
A procedure is distinguishable from a generic-case
if it is distinguishable from all the procedures that appear in that generic-case
procedure list.
Similarly two generic-case
are distinguishable if all the procedure belonging to the first generic-case
list are distinguishable from all the procedure that appears in the second generic-case
list.
A similar changes will appear in the specification of a type in order to have a generic_case type bound list.
I haven’t thought at the possible changes yet: like that in an extended type all generic_case list should be TKR equal (first procedure with first procedure of the parent, etc. apart the passed object), so that a compiler can generate a single vtable, or…
I haven’t thought about the interaction with the new generic
facility coming in Fortran 202y, but I don’t know enough of the latter.
I tried to propose something that is not breaking actual Fortran, but I may have failed of course.
I like to know what you think about this, if it could be included in Fortran 203z.
And apologize me for the English (I’m not an English native speaker).
Cheers