https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128144

            Bug ID: 128144
           Summary: [F03] ICE in gfc_conv_component_ref with type-bound
                    call through inferred ASSOCIATE name
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jvdelisle at gcc dot gnu.org
  Target Milestone: ---

A type-bound procedure call (or procedure pointer component call)
through a component of an associate name whose selector is a
contained function not yet parsed gives an ICE.  If another type has
a component and binding of the same names, the wrong procedure is
called instead (wrong code) or a bogus type mismatch is reported.

module m
  type :: leaf_t
     integer :: bar = 0
  contains
    procedure :: get
  end type
  type :: mid_t
     class(leaf_t), allocatable :: c2
  end type
contains
  integer function get (this)
    class(leaf_t), intent(in) :: this
    get = this%bar + 100
  end function
end module
program p
  use m
  implicit none
  integer :: i
  associate (q => cfcn ())
    i = q%c2%get ()
  end associate
  if (i /= 105) stop 1
contains
  function cfcn () result (y)
    class(mid_t), allocatable :: y
    allocate (y)
    allocate (y%c2)
    y%c2%bar = 5
  end function
end program

$ gfortran pr.f90
internal compiler error: in gfc_conv_component_ref, at
fortran/trans-expr.cc:2939

Moving cfcn into the module, or giving it a TYPE(mid_t) result,
avoids the ICE.  Found while reviewing the fix for PR126968.

Reply via email to