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

Overloaded operator for derived type undefined when imported from a wrapper module

Milan_Curcic
Beginner
1,133 Views

The following code does not compile with Intel Fortran v16, v17, on x86-64 Linux:

module mymod
implicit none

type :: mytype
  private
  integer :: a
  contains
  procedure,private :: eq
  generic :: operator(==) => eq
endtype mytype

interface mytype
  module procedure :: constructor
endinterface mytype

contains

type(mytype) function constructor(a)
  integer,intent(in),optional :: a
  if(present(a))then
    constructor % a = a
  else
    constructor % a = 0
  endif
endfunction constructor

logical function eq(m0,m1)
  class(mytype),intent(in) :: m0
  class(mytype),intent(in) :: m1
  eq = m0 % a == m1 % a
endfunction eq

endmodule mymod

module wrapper_module
use mymod,only:mytype
endmodule wrapper_module

program test
use wrapper_module
implicit none

write(*,*)mytype() == mytype(0)

endprogram test

The compiler does not seem to resolve the overloaded == operator for mytype:

$ ifort test.f90 
test.f90(44): error #6355: This binary operation is invalid for this data type.
write(*,*)mytype() == mytype(0)
----------^
test.f90(44): error #6355: This binary operation is invalid for this data type.
write(*,*)mytype() == mytype(0)
----------------------^
compilation aborted for test.f90 (code 1)

If the main program accesses mytype directly from mymod, the program compiles and executes as expected.

If the main program accesses mytype from wrapper_module, and wrapper module accesses mytype via "use mymod", the program compiles and executes as expected.

If the main program accesses mytype from wrapper_module, and wrapper module accesses mytype via "use mymod,only:mytype" (the example code above), the compilation fails with the above message. I think this is unexpected behavior.

The code compiles and executes as expected when compiled with gfortran 5.x

Thanks,

milan

 

 

0 Kudos
5 Replies
Steven_L_Intel1
Employee
1,133 Views

Thanks - this is an issue we're already working on. Issue ID is DPD200374263.

0 Kudos
milan_c_1
Beginner
1,133 Views

Just a follow-up, the issue remains as of Intel Fortran 19.0.1.144 Build 20181018.

 

Cheers,

milan

0 Kudos
Izaak_Beekman
New Contributor II
1,132 Views

This still seems to be present even in the latest compiler. Any updates on the Intel side?

0 Kudos
Juergen_R_R
Valued Contributor II
1,133 Views

For me this works with ifort v19.0.3 and v19.0.4 as well as with the beta version of 19.1.0. So it seems that this bug has been fixed.

0 Kudos
milan_c_1
Beginner
1,133 Views

Thanks Juergen, it looks like it's time for an update. :)

0 Kudos
Reply