Skip to content

Duplicated interfaces for Fortran generic interfaces, if there are two interface blocks and interface also from used module #149

@haraldkl

Description

@haraldkl

Trying to generate code for the following example:

module other_module
  implicit none

  interface sub
    module procedure sub_real
  end interface sub

contains
  subroutine sub_real(me)
    real :: me
  end subroutine sub_real
end module other_module

module tem_matrix_module
  use other_module, only: sub
  implicit none

  interface sub
    module procedure sub_int
  end interface sub

  interface sub
    module procedure sub_logical
  end interface sub


contains
    subroutine sub_int(me)
      integer :: me
    end subroutine sub_int

    subroutine sub_logical(me)
      logical:: me
    end subroutine sub_logical
end module tem_matrix_module

results in duplicated interface blocks after transforming to xml and back again:

$ F_Front mwe.f90 -o mwe.xml -I.
$ F_Back -l mwe.xml -o mwe_back.f90

Resulting mwe_back.f90:

MODULE other_module
 INTERFACE sub
  MODULE PROCEDURE sub_real
 END INTERFACE

CONTAINS
 SUBROUTINE sub_real ( me )

  REAL :: me

 END SUBROUTINE sub_real

END MODULE other_module

MODULE tem_matrix_module
 USE other_module , ONLY: sub
 INTERFACE sub
  MODULE PROCEDURE sub_int
  MODULE PROCEDURE sub_logical
 END INTERFACE
 INTERFACE sub
  MODULE PROCEDURE sub_int
  MODULE PROCEDURE sub_logical
 END INTERFACE

CONTAINS
 SUBROUTINE sub_int ( me )

  INTEGER :: me

 END SUBROUTINE sub_int

 SUBROUTINE sub_logical ( me )

  LOGICAL :: me

 END SUBROUTINE sub_logical

END MODULE tem_matrix_module

Which is illegal code, while the original was legal.

It may appear strange to have two separate generic interface blocks for the same generic name in the original code, but this arises because we generate the code for different data-types in a pre-processing step.

If the other_module is not used, the transformation works as expected resulting in two interface blocks with only a single module procedure, as in the original code.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions