Quantcast
Channel: Intel® Fortran Compiler
Viewing all articles
Browse latest Browse all 3270

Generic interface with same name as derived type still not working?

$
0
0

Hi,

I am trying to use generic interface with same name as derived type, but it does not work with an Intel compiler in some cases. I have read

https://software.intel.com/en-us/forums/topic/283849

https://software.intel.com/en-us/forums/topic/271401

but I am still getting errors. I have originally got the codes list.f90 and link.f90 from

https://www.pgroup.com/lit/samples/list.f90

https://www.pgroup.com/lit/samples/link.f90

to understand

4. Case Study: Data Polymorphic Linked List

https://www.pgroup.com/lit/articles/insider/v3n2a2.htm

I can compile the original codes with

/opt/pgi/linux86-64/13.2/bin/pgf90

but not with

/opt/intel/composer_xe_2013_sp1.2.144/bin/intel64/ifort

Therefore, I have simplified the code to reproduce the error. When I compile the codes link_simple.f90

module link_mod
  implicit none
  private
  public :: link, constructor
  type link
    private
    class(*), pointer :: value => null() ! value stored in link
    type(link), pointer :: next => null()! next link in list
  contains
    procedure :: nextLink    ! return next pointer
  end type link

  interface link
    module procedure constructor ! construct/initialize a link
  end interface

contains

  function nextLink(this)
    class(link) :: this
    class(link), pointer :: nextLink
    nextLink => this%next
  end function nextLink

  function constructor(value, next)
    class(link),pointer :: constructor
    class(*) :: value
    class(link), pointer :: next
    allocate(constructor)
    constructor%next => next
    allocate(constructor%value, source=value)
  end function constructor

end module link_mod

and list_simple.f90

module list_mod
  use link_mod
  implicit none
  private
  public :: list
  type list
    private
    class(link), pointer :: firstLink => null() ! first link in list
    class(link), pointer :: lastLink => null()  ! last link in list
  contains
    procedure :: addValue    ! add class(*) to linked list
  end type list

contains

  subroutine addValue(this, value)
    class(list) :: this
    class(*) :: value
    class(link), pointer :: newLink

!   newLink => link(value, this%firstLink)  ! this works
    newLink => link(value, this%lastLink%nextLink())  ! this doesn't work
!   newLink => constructor(value, this%lastLink%nextLink())  ! this works
  end subroutine addValue

end module list_mod

I get the errors

$ which ifort
/opt/apps/intel/13/composer_xe_2013.2.146/bin/intel64/ifort
$ ifort -c link_simple.f90 list_simple.f90
list_simple.f90(23): error #6292: The parent type of this field is use associated with the PRIVATE fields attribute   [VALUE]
    newLink => link(value, this%lastLink%nextLink())  ! this doesn't work
--------------------^
list_simple.f90(23): error #6292: The parent type of this field is use associated with the PRIVATE fields attribute
    newLink => link(value, this%lastLink%nextLink())  ! this doesn't work
---------------------------^
list_simple.f90(23): error #6680: A constant is not permitted in this context.
    newLink => link(value, this%lastLink%nextLink())  ! this doesn't work
---------------^
compilation aborted for list_simple.f90 (code 1)

I can compile the codes when using line 21 or 23, instead of 22, of list_simple.f90.


Viewing all articles
Browse latest Browse all 3270

Trending Articles



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