Search code examples
genericsfortranprocedurefortran2003

There is no matching specific subroutine for this type bound generic subroutine call


I have a type with two bound procedures (GetAsScalar & GetAsList) under a generic procedure (GetValue):

type, extends(TObject)  ::  TKeyword
    character(len=:), allocatable               ::  fValue

contains
    procedure, private                          ::  GetAsScalar
    procedure, private                          ::  GetAsList        

    generic                                     ::  GetValue    =>  &
                                                    GetAsScalar,    &
                                                    GetAsList
end type TKeyword

The routines signatures are these:

subroutine GetAsScalar (this, value, status)
    !Arguments-------------------------------------------------------------
    class(TKeyword)                                 ::  this
    class(*), target                                ::  value
    logical, optional                               ::  status

    !...
end subroutine GetAsScalar

subroutine GetAsList (this, value, status)
    !Arguments-------------------------------------------------------------
    class(TKeyword)                                 ::  this
    class(*), pointer                               ::  value(:)
    logical, optional                               ::  status

    !...
end subroutine GetAsList

Internally, the TKeyword object stores a string.

If I try to use it in the following way (bellow), I get a compilation error: "There is no matching specific subroutine for this type bound generic subroutine call"

class(TKeyword), pointer :: key
class(*), pointer :: p(:)
allocate (integer::p(3))

!Code to read instantiate the TKeyword object

call key%GetValue(p, status)

select type (p)
type is (integer)
    write (*,*) p
end select

If I remove the GetASScalar from the generic association and make it public, the following code works as expected:

class(TKeyword), pointer :: key
class(*), pointer :: p(:)
allocate (integer::p(3))

!Code to read instantiate the TKeyword object

call key%GetAsList(p, status)

select type (p)
type is (integer)
    write (*,*) p
end select

When passing a scalar (integer, real, character, etc), the GetAsScalar routine is called without problems.

I would like to know why this is happening. What am I missing in this "generic thing" that makes the compiler unable to recognize my subroutine under the generic? There is a way to make this work? Would be something related with the routine signature?

I'm using Intel Fortran 15.0.1.148


Solution

  • Acoording to answers in the intel fortran forum (https://software.intel.com/en-us/forums/topic/537784#comment-1809520), this code should work and the compiler error is probably a small bug in the compiler.

    An issue was escalated by Steve Lionel (Intel).

    Thanks.