https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126968
--- Comment #2 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Jerry DeLisle <[email protected]>: https://gcc.gnu.org/g:d6d1dedff578726b9d0ed55d0ebc28a9dc5b543c commit r17-5582-gd6d1dedff578726b9d0ed55d0ebc28a9dc5b543c Author: Jerry DeLisle <[email protected]> Date: Sat Oct 24 10:49:03 2026 -0400 fortran: [PR126968] ICE for wrongly guessed inferred ASSOCIATE type When an ASSOCIATE selector is a function that has not been parsed yet, primary.cc types the associate name by guessing: it takes the first accessible derived type that has a component of the name being referenced. resolve_assoc_var later corrects the associate name's type from the resolved selector, and gfc_fixup_inferred_type_refs repaired the reference chain. That repair only reset ref->u.c.sym and left ref->u.c.component pointing into the guessed type. When the guess was wrong, the component and the type it is referenced from no longer belonged together, which reached the backend and gave internal compiler error: in gfc_conv_component_ref, at fortran/trans-expr.cc:3010 Bind each component reference to the corrected type by looking it up again by name, walking the whole chain so that nested references are corrected too. After a CLASS component, a '_data', '_vptr' or '_len' reference is looked up in that component's class container, and any other reference is bound to its declared type, since the '_data' reference in between can be explicit or implicit. Rebinding stops at '_vptr' and '_len'. The array reference after a component was also built from the guessed component, so it could carry the wrong bounds, or be missing or spurious when only one of the two components is an array. Make it agree with the real component: use its array spec, drop or supply a full array reference, or turn a misparsed section of a scalar character component back into a substring. Components are now also checked for PRIVATE access in the real type. Assisted-by: Claude Opus 5.5 PR fortran/126968 gcc/fortran/ChangeLog: * resolve.cc (fixup_inferred_component_array_ref): New function. (gfc_fixup_inferred_type_refs): Look each component reference up again by name in the corrected derived type and update both u.c.sym and u.c.component. Walk the whole reference chain instead of stopping at the first component. Look up '_data', '_vptr' and '_len' in the class container of the preceding CLASS component. Check component access. Use fixup_inferred_component_array_ref on the reference after each rebound component. gcc/testsuite/ChangeLog: * gfortran.dg/associate_89.f90: New test. * gfortran.dg/associate_91.f90: New test. * gfortran.dg/associate_93.f90: New test. * gfortran.dg/associate_94.f90: New test.
