module ice5 type::a_type contains procedure::a_subroutine_1 procedure::a_subroutine_2 end type a_type contains subroutine a_subroutine_1(this) class(a_type)::this real::res res=this%a_subroutine_2() end subroutine a_subroutine_1 subroutine a_subroutine_2(this) class(a_type)::this end subroutine a_subroutine_2 end module ice5 gfortran -c ice5.f03 ice5.f03:11.8: res=this%a_subroutine_2() 1 Fehler: 'a_subroutine_2' at (1) should be a FUNCTION f951: interner Compiler-Fehler: in gfc_add_component_ref, bei fortran/class.c:77 Obvioulsly the code is nonsense and the compiler generates a proper error message, so there is little need to fix this ICE. However, it is an ICE.
Confirmed. Btw the same thing happens if you treat a type-bound function as if it were a subroutine: module ice5 type::a_type contains procedure::a_subroutine_1 procedure::a_subroutine_2 end type a_type contains real function a_subroutine_1(this) class(a_type)::this real::res !res=this%a_subroutine_2() end function subroutine a_subroutine_2(this) class(a_type)::this call this%a_subroutine_1() end subroutine end module ice5 Error: 'a_subroutine_1' at (1) should be a SUBROUTINE f951: internal compiler error: in gfc_add_component_ref, at fortran/class.c:77
This is easily fixed by the following patch: Index: gcc/fortran/resolve.c =================================================================== --- gcc/fortran/resolve.c (revision 160833) +++ gcc/fortran/resolve.c (working copy) @@ -5498,7 +5498,8 @@ resolve_typebound_function (gfc_expr* e) /* Treat the call as if it is a typebound procedure, in order to roll out the correct name for the specific function. */ - resolve_compcall (e, &name); + if (resolve_compcall (e, &name) == FAILURE) + return FAILURE; ts = e->ts; /* Then convert the expression to a procedure pointer component call. */ @@ -5571,7 +5572,8 @@ resolve_typebound_subroutine (gfc_code *code) if (code->expr1->value.compcall.tbp->is_generic) genname = code->expr1->value.compcall.name; - resolve_typebound_call (code, &name); + if (resolve_typebound_call (code, &name) == FAILURE) + return FAILURE; ts = code->expr1->ts; /* Then convert the expression to a procedure pointer component call. */ I will regtest this now and in case of success commit it as obvious later ...
Subject: Bug 44558 Author: janus Date: Thu Jun 17 22:15:30 2010 New Revision: 160948 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=160948 Log: 2010-06-17 Janus Weil <janus@gcc.gnu.org> PR fortran/44558 * resolve.c (resolve_typebound_function,resolve_typebound_subroutine): Return directly in case of an error. 2010-06-17 Janus Weil <janus@gcc.gnu.org> PR fortran/44558 * gfortran.dg/typebound_call_15.f03: New. Added: trunk/gcc/testsuite/gfortran.dg/typebound_call_15.f03 Modified: trunk/gcc/fortran/ChangeLog trunk/gcc/fortran/resolve.c trunk/gcc/testsuite/ChangeLog
Fixed with r160948. Closing. Thanks for the report!