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

Ambiguous generic interface

Blane_J_
New Contributor I
1,291 Views

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
1 Solution
Arjen_Markus
Honored Contributor I
1,291 Views

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

View solution in original post

0 Kudos
4 Replies
Arjen_Markus
Honored Contributor I
1,291 Views

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
Blane_J_
New Contributor I
1,291 Views

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

0 Kudos
Arjen_Markus
Honored Contributor I
1,292 Views

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

0 Kudos
Blane_J_
New Contributor I
1,291 Views

Arjen Markus wrote:

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

Thanks I got it.

0 Kudos
Reply