Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
New Contributor I
36 Views

Ambiguous generic interface

Jump to solution

Hi, everyone. The following code puzzles me:

module test

    type :: tp
        private
        integer :: i
    contains
        private
        generic, public :: ge => sub1,  &
                                 sub2
        procedure, pass :: sub1
        procedure, pass :: sub2
    end type tp

    contains
    
    subroutine sub1(this, s)
        class(ab), intent(in) :: this
        class(*),  intent(in) :: s
    end subroutine sub1
    
    subroutine sub2(this, s)
        class(ab), intent(in) :: this
        integer,   intent(in) :: s
    end subroutine sub2

end module test

And the compiler says:

Ambiguous generic interface GE: previously declared specific procedure SUB1 is not distinguishable from this declaration. [SUB2]

Is it a problem to distinguish INTEGER from unlimited polymorphic ?

0 Kudos

Accepted Solutions
Highlighted
Valued Contributor II
36 Views

Sure it is possible, but you

Jump to solution

Sure it is possible, but you need an additional argument to solve the ambiguity.

View solution in original post

0 Kudos
4 Replies
Highlighted
Valued Contributor II
36 Views

Perhaps the other way around:

Jump to solution

Perhaps the other way around: an unlimited polymorphic variable can have any type, so indeed it can not be distinguished by type alone.

0 Kudos
Highlighted
New Contributor I
36 Views

SO it's not possible to have

Jump to solution

SO it's not possible to have sub/funcs which have unlimited polymorphic argument in overloaded generics ?

0 Kudos
Highlighted
Valued Contributor II
37 Views

Sure it is possible, but you

Jump to solution

Sure it is possible, but you need an additional argument to solve the ambiguity.

View solution in original post

0 Kudos
Highlighted
New Contributor I
36 Views

Quote:Arjen Markus wrote:

Jump to solution

Arjen Markus wrote:

Sure it is possible, but you need an additional argument to solve the ambiguity.

Thanks I got it.

0 Kudos