Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
Welcome to the Intel Community. If you get an answer you like, please mark it as an Accepted Solution to help others. Thank you!
26755 Discussions

Error for binary operation involving polymorphic variables

Christopher_M_
Beginner
92 Views

I have found that the following code (which compiles with gfortran) produceses an error with ifort 17.0.1.

module test_mod
  implicit none

  type, abstract :: bin_op_type
  contains
    procedure(bin_op), deferred :: is_equal
    generic :: operator(==) => is_equal
  end type bin_op_type

  abstract interface
     logical function bin_op(this,other)
       import :: bin_op_type
       class(bin_op_type), intent(in) :: this, other
     end function bin_op
  end interface

  type, extends(bin_op_type) :: example_type
     real :: contents
  contains
    procedure :: is_equal => example_is_equal
  end type example_type

contains

  logical function example_is_equal(this,other)
    class(example_type), intent(in) :: this
    class(bin_op_type), intent(in) :: other
    example_is_equal = .true.
  end function example_is_equal

end module

module dependency
  use test_mod
  implicit none

contains
  
  subroutine bug_example(obj1,obj2)
    class(example_type) :: obj1
    class(bin_op_type)  :: obj2
    logical :: result
    result = (obj1 == obj2) !This compiles
    result = (obj2 == obj1) !This doesn't
  end subroutine bug_example

end module

It produces the following error message:

binary_op.f90(44): error #6355: This binary operation is invalid for this data type.   [OBJ2]
    result = (obj2 == obj1) !This doesn't
--------------^
binary_op.f90(44): error #6355: This binary operation is invalid for this data type.   [OBJ1]
    result = (obj2 == obj1) !This doesn't
----------------------^
compilation aborted for binary_op.f90 (code 1)

 

0 Kudos
1 Reply
Kevin_D_Intel
Employee
92 Views

Thank you for the convenient reproducer. Our apologies for the additional problem. I escalated this to Development and inquired about any possible work around.

(Internal tracking id: DPD200417363)

Reply