Quantcast
Channel: Intel® Fortran Compiler for Linux* and macOS*
Viewing all articles
Browse latest Browse all 2583

Incorrect behavior with inheritance when using submodules?

$
0
0

Hello,

 

 

I have a test program which I believe is producing correct answers when compiled with ifort Version 18.0.0.128 Build 20170811 and incorrect answers when compiled with the newer ifort Version 18.0.1.163 Build 20171018.  In both cases, the code compiles with no warnings or errors.

I believe the code is valid, although it is certainly possible I am misunderstanding how these features work.  The problem occurs when I use a submodule to separate the implementation from the interfaces, and I have a type which extends another, and both types have a procedure with the same name.  If I don't use a submodule, and put all declarations in the "contains" section, it works fine.  Here is a reproducer:

!-------------------------------------------------------------------------------
! Module Model
!-------------------------------------------------------------------------------
module Model

  implicit none

  private

  !-------------------------------------------------------------------------------
  ! parent_model_type
  !-------------------------------------------------------------------------------
  public :: parent_model_type

  type :: parent_model_type
    private
  contains
    procedure :: go
  end type parent_model_type

  !-------------------------------------------------------------------------------
  ! child_model_type
  !-------------------------------------------------------------------------------
  public :: child_model_type

  type, extends(parent_model_type) :: child_model_type
    private
  contains
    procedure :: go => go_child
  end type child_model_type

  interface
    module subroutine go_child(this)
      class(child_model_type) :: this
    end subroutine go_child
  end interface

contains

  !-----------------------------------------------------------------------
  ! go
  !-----------------------------------------------------------------------
  subroutine go(this)

    class(parent_model_type) :: this

    print *, "Parent model is going"

  end subroutine go

end module Model


!-------------------------------------------------------------------------------
! Submodule Child_Model
!-------------------------------------------------------------------------------
submodule(Model) Child_Model

  implicit none

contains

  !-----------------------------------------------------------------------
  ! go_child
  !-----------------------------------------------------------------------
  module subroutine go_child(this)

    class(child_model_type) :: this

    print *,"Child model is going"

  end subroutine go_child

end submodule Child_Model


!-------------------------------------------------------------------------------
! Program test
!-------------------------------------------------------------------------------
program Test

  use Model, only : parent_model_type, child_model_type

  implicit none

  type(parent_model_type) :: parent
  type(child_model_type)  :: child

  call parent%go()
  call child%go()

end program Test

When I run this code compiled with ifort Version 18.0.1.163 Build 20171018 I get the wrong answer:

$ ./test.exe
 Parent model is going
 Parent model is going
$

When I run this code compiled with ifort Version 18.0.0.128 Build 20170811 I get the correct answer:

$ ./test.exe
 Parent model is going
 Child model is going
$

Is this a bug in the newer 18.1.163 compiler?  Or am I doing something wrong?

Thank you for your time,

Chris


Viewing all articles
Browse latest Browse all 2583

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>