I have two simple source files, one.f90 (compiles ok) and two.f90.
and two.f90. the latter fails to compile with error 0155 (interface is not compatible with parent’s interface for type bound procedure comparePoint). Can you help me spot what is wrong?
thanks - Rick
module one
type, abstract, public :: comparable
!
contains
procedure(boolean_binary) :: compareTo
!
end type comparable
abstract interface
!
logical function boolean_binary(this, other)
import :: comparable
class(comparable), intent(in) :: this
class(comparable), intent(in) :: other
end function boolean_binary
!
end interface
end module one
module two
use one
type, public, extends(comparable) :: point
contains
procedure :: compareTo => comparePoint
end type point
contains
logical function comparePoint(this, other)
class(point), intent(in) :: this
class(point), intent(in) :: other
comparePoint = .true.
end function comparePoint
end module two
Hi Rick,
The interface for comparePoint in module two is not compatible with the parent interface in module one. The second argument in comparePoint must be the same as the parent’s second argument. In general, the arguments for a child type bound procedure must match the parent’s, except for the passed object argument (in which case, the passed object argument must be the same as the type defining the type bound procedure).
To correct the error, you should change the second argument in comparePoint from:
class(point), intent(in) :: other
to
class(comparable), intent(in) :: other
Also you need to add the “deferred” attribute on the parent compareTo (deferred must appear if an interface is used in a type bound procedure definition).
For example.
procedure(boolean_binary), deferred :: compareTo
Our compiler should have reported an error on that as well, but didn’t. We will investigate that.
Below is the complete corrected code:
module one
type, abstract, public :: comparable
!
contains
procedure(boolean_binary),deferred :: compareTo
!
end type comparable
abstract interface
!
logical function boolean_binary(this, other)
import :: comparable
class(comparable), intent(in) :: this
class(comparable), intent(in) :: other
end function boolean_binary
!
end interface
end module one
module two
use one
type, public, extends(comparable) :: point
contains
procedure :: compareTo => comparePoint
end type point
contains
logical function comparePoint(this, other)
class(point), intent(in) :: this
class(comparable), intent(in) :: other
comparePoint = .true.
end function comparePoint
end module two