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!

Ambiguous generic interface

Blane_J_
New Contributor I
359 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
Valued Contributor III
359 Views

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

View solution in original post

4 Replies
Arjen_Markus
Valued Contributor III
359 Views

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

Blane_J_
New Contributor I
359 Views

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

Arjen_Markus
Valued Contributor III
360 Views

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

View solution in original post

Blane_J_
New Contributor I
359 Views

Arjen Markus wrote:

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

Thanks I got it.

Reply