https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116837
Bug ID: 116837 Summary: Generic type bound is not correctly resolved Product: gcc Version: 14.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran Assignee: unassigned at gcc dot gnu.org Reporter: comptes at ugo235 dot fr Target Milestone: --- The following code does not compile: ``` module foo implicit none type ta integer :: i = 0 contains procedure :: sub1, sub2 generic :: sub => sub1, sub2 end type contains elemental subroutine sub1(this,that) class(ta), intent(inout) :: this integer, intent(in) :: that this%i = that end subroutine subroutine sub2(this,that) class(ta), intent(inout) :: this integer, intent(in) :: that(:) this%i = sum(that(:)) end subroutine end module foo program bar use foo implicit none type(ta) :: a call a% sub( 1 ) print*, a%i call a% sub( [1,2] ) print*, a%i end ``` The error message is: ``` 36 | call a% sub( [1,2] ) | 1 Error: Actual argument at (1) for INTENT(INOUT) dummy 'this' of ELEMENTAL subroutine 'sub1' is a scalar, but another actual argument is an array ``` Because the first argument is a scalar, the compiler picks the `sub1` routine, then complains that the second argument is an array, instead of picking the `sub2` routine that has the appropriate interface. Intel ifx and flang-new do correctly compile this code (tested on godbolt.org). Note that the problem is specific to type-bound procedures, as this version with a generic interface is compiled without any error and gives the expected result: ``` module foo implicit none type ta integer :: i = 0 end type interface sub module procedure :: sub1, sub2 end interface contains elemental subroutine sub1(this,that) class(ta), intent(inout) :: this integer, intent(in) :: that this%i = that end subroutine subroutine sub2(this,that) class(ta), intent(inout) :: this integer, intent(in) :: that(:) this%i = sum(that(:)) end subroutine end module foo program bar use foo implicit none type(ta) :: a call sub( a, 1 ) print*, a%i call sub( a, [1,2] ) print*, a%i end ```