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!
26733 Discussions

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

Lewis__Rubin
Novice
143 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
Black Belt
143 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

2 Replies
IanH
Black Belt
144 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

Lewis__Rubin
Novice
143 Views

IanH,

Excellent, Thank you very much.

Best wishes,
Rubin

Reply