Fortran: Fixes spurious error with inferred-type ASSOCIATE names
GCC's Fortran compiler no longer produces an incorrect 'Expected argument list' error for component references on inferred-type ASSOCIATE names.
This commit fixes a spurious ‘Expected argument list’ error in GCC’s Fortran compiler when processing component references on inferred-type ASSOCIATE names, as reported in PR125531. Previously, the parser would incorrectly treat a component name as a type-bound procedure. The fix in gfc_match_varspec now retries gfc_find_component with noaccess=true if the default search fails, ensuring that the resolution pass can correctly substitute the final type for inferred-type ASSOCIATE names, preventing false positives.
In Details
This change in gcc/fortran/primary.cc, specifically within gfc_match_varspec, resolves PR125531 by addressing an issue where parsing component references on inferred-type ASSOCIATE names led to an erroneous 'Expected argument list' error. The parser was incorrectly matching the component name as a type-bound procedure. The fix involves modifying the gfc_match_varspec logic: before erroring on a zero-argument COMPCALL, it now checks for a same-named data component. Crucially, for inferred-type ASSOCIATE names, gfc_find_component is retried with noaccess=true if the initial atte…
For Context
This update to GCC, the Fortran compiler, fixes a specific error message that would incorrectly appear for some Fortran programs. In Fortran, ASSOCIATE constructs allow you to refer to a complex expression or an object with a simpler name. When these ASSOCIATE names have their type 'inferred' (meaning the compiler figures out the type automatically), and you then tried to access a 'component' (a part) of that associated name, the compiler would sometimes mistakenly think you were trying to call a function, leading to an 'Expected argument list' error. This fix teaches the compiler to correctly distinguish between accessing a data component and calling a function in these situations, making the compiler more accurate and less prone to giving misleading error messages for valid Fortran code.