Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Ifort bug: Defined assignment not recognized

Bálint_A_
Beginner
375 Views

Dear Intel developer,

The ifort compiler (16.0.0 20150815) refuses to compile valid Fortran 2003 code if this contains overridden assignment in a polymorphic type. The self containing code below demonstrates the issue. The compiler stops with the error message

test.F90(59): error #6197: An assignment of different structure types is invalid.   [MYEXT1]
  pExt1 = myExt1

although an assignment operator for the polymorphic variable pExt1 is defined. Other Fortran 2003 compilers seem to have no problems with it.

Best regards,

Bálint

module typedefs
  implicit none

  type :: Base
  contains
    procedure :: assignFrom => Base_assignFrom
    generic :: assignment(=) => assignFrom
  end type Base

  type, extends(Base) :: Extended
    integer :: data
  contains
    procedure :: assignFrom => Extended_assignFrom
  end type Extended

contains

  subroutine Base_assignFrom(this, other)
    class(Base), intent(inout) :: this
    class(Base), intent(in) :: other

    select type (other)
    type is (Base)
      continue
    class default
      print *, "Wrong data type for Base%assignFrom"
      error stop 1
    end select

  end subroutine Base_assignFrom


  subroutine Extended_assignFrom(this, other)
    class(Extended), intent(inout) :: this
    class(Base), intent(in) :: other

    select type (other)
    type is (Extended)
      this%data = other%data
    class default
      print *, "Wrong data type for Extended%assignFrom"
      error stop 1
    end select

  end subroutine Extended_assignFrom

end module typedefs


program test
  use typedefs
  implicit none

  type(Extended) :: myExt1
  class(Base), pointer :: pExt1

  myExt1%data = -1
  allocate(pExt1, source=myExt1)
  pExt1 = myExt1
  select type (pExt1)
  type is (Extended)
    print *, "VALUE:", pExt1%data
  class default
    print *, "Unexpected type"
  end select
  
end program test

 

0 Kudos
9 Replies
Steven_L_Intel1
Employee
375 Views

Thanks, we'll take a look.

0 Kudos
FortranFan
Honored Contributor II
375 Views

If I recall correctly, 'polymorphic assignment' is a Fortran 2008 feature that is not yet supported by Intel Fortran.  Even when it does get supported, I think the generic resolution issue, similar to the other incident you posted (https://software.intel.com/en-us/forums/intel-fortran-compiler-for-linux-and-mac-os-x), will remain given how you put together the Base and Extended derived types.  So with polymorphic variable pExt1 declared as 'class(Base', my impression is you will still need to do along the following lines but I'm open to the possibility of being wrong about this:

program test

   use typedefs

   implicit none

   type(Extended) :: myExt1
   class(Base), pointer :: pExt1

   myExt1%data = -1
   allocate(pExt1, source=myExt1)
   select type (pExt1)
      type is (Extended)
         pExt1 = myExt1
         print *, "VALUE:", pExt1%data
      class default
         print *, "Unexpected type"
   end select

end program test

 

0 Kudos
Bálint_A_
Beginner
375 Views

The assignment to an allocatable polymorphic variable is indeed Fortran 2008. However, here we have an assignment to a static polymorphic variable and that is Fortran 2003, as far as I know. I can not point out the part in the standard, but I've checked it also with another commercial compiler which I have found the most reliable so far when in doubt about the standard, and it compiles the code in F2003 mode.

Also, thanks for the workaround, but that won't help in my situation, as in my application I can not know the possible types in advance. I would like to implement a general purpose container holding arbitrary extensions of a given derived type with user overridden assignments.
 

0 Kudos
Steven_L_Intel1
Employee
375 Views

Intrinsic assignment to a polymorphic variable is not standard F2003:

17 An intrinsic assignment statement is an assignment statement that is not a defined assignment
18 statement (7.4.1.4). In an intrinsic assignment statement, variable shall not be polymorphic, and
19 (1) If expr is an array then variable shall also be an array,
20 (2) Either variable shall be an allocatable array of the same rank as expr or the shapes of
21 variable and expr shall conform, and
(3) The declared types of variable 1 and expr shall conform as specified in Table 7.8.

However, this is defined assignment which is not so restricted.

0 Kudos
Bálint_A_
Beginner
375 Views

Thank you for the clarification! I've changed the title of the thread to contain the correct wording.

0 Kudos
Steven_L_Intel1
Employee
375 Views

Escalated as issue DPD200409351. I will update this thread when there is news.

0 Kudos
Juergen_R_R
Valued Contributor I
375 Views

Apparently this thread was never updated but this is definitely fixed now in recent versions of ifort. 

0 Kudos
may_ka
Beginner
375 Views

Not fixed in 17.07 and 18.03

Cheers

0 Kudos
Juergen_R_R
Valued Contributor I
375 Views

Wait, my check wasn't proper: apparently it _is_ fixed in ifort v19beta! 

 

0 Kudos
Reply