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

error #8638 occured while binding IO for derived type and its extended type

Lewis__Rubin
Novice
494 Views

While using object-oriented programming in FORTRAN, I want to implement the user-defined IO for the derived type and its extended type. The sample code is

module test
	implicit none

	type :: base
	contains
	procedure :: ReadBase
	generic :: read(unformatted) => ReadBase
	end type base

	type, extends(base) :: derived
	contains
	procedure :: ReadDerived
	generic :: read(unformatted) => ReadDerived
	end type derived

contains

	subroutine ReadBase(dtv,unit,stat,msg)
	implicit none
	class(base) :: dtv
	integer :: unit, stat
	character(*) :: msg

	end subroutine ReadBase

	subroutine ReadDerived(dtv,unit,stat,msg)
	implicit none
	class(derived) :: dtv
	integer :: unit, stat
	character(*) :: msg
	
	end subroutine ReadDerived

end module test

After compiling, the error #8638 occurred, like this,

error #8638: The type/rank signature for arguments of this specific subroutine is identical to another specific subroutine that shares the same defined I/O.   [READBASE]

Does anyone have a clue to resolve this problem?

Best wishes,
Rubin

0 Kudos
1 Solution
IanH
Honored Contributor II
494 Views

You are declaring a totally separate specific binding called ReadDerived in the extension type, but what you actually want to do is override the existing binding.

Type, extends (base) :: derived
...
Contains
  Procedure :: ReadBase => ReadDerived
End type derived
...

No need for another binding, no need to try and extend the generic binding with another specific.  You just want a different procedure selected for the particular specific binding based on the dynamic type of the relevant object.

(The compiler resolves a generic binding to a specific binding at compile time based on the declared type of the relevant object(s).  That specific binding is then resolved to a particular specific procedure at runtime based on the dynamic type of the relevant object. UDDTIO isn't anything special in this regard.)

 

View solution in original post

0 Kudos
2 Replies
IanH
Honored Contributor II
495 Views

You are declaring a totally separate specific binding called ReadDerived in the extension type, but what you actually want to do is override the existing binding.

Type, extends (base) :: derived
...
Contains
  Procedure :: ReadBase => ReadDerived
End type derived
...

No need for another binding, no need to try and extend the generic binding with another specific.  You just want a different procedure selected for the particular specific binding based on the dynamic type of the relevant object.

(The compiler resolves a generic binding to a specific binding at compile time based on the declared type of the relevant object(s).  That specific binding is then resolved to a particular specific procedure at runtime based on the dynamic type of the relevant object. UDDTIO isn't anything special in this regard.)

 

0 Kudos
Lewis__Rubin
Novice
494 Views

IanH,

Excellent, Thank you very much.

Best wishes,
Rubin

0 Kudos
Reply