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

試著忘記壹切 提交于 2019-12-12 01:48:15

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/27705554/there-is-no-matching-specific-subroutine-for-this-type-bound-generic-subroutine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!