Bug 125531 - Inferred-type ASSOCIATE name gives spurious "Expected argument list" when data component shares name
Summary: Inferred-type ASSOCIATE name gives spurious "Expected argument list" when dat...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 16.0
: P3 normal
Target Milestone: ---
Assignee: Jerry DeLisle
URL:
Keywords:
Depends on:
Blocks: 125515
  Show dependency tree / graph
 
Reported: 2026-05-31 20:02 UTC by Jerry DeLisle
Modified: 2026-06-21 02:49 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2026-05-31 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jerry DeLisle 2026-05-31 20:02:32 UTC
When an ASSOCIATE construct uses a contained function as its selector and the result type has a data component whose name also matches a type-bound procedure name, gfortran spuriously rejects the data-component access with "Expected argument list".

  program test
    implicit none

    type :: args_t
      integer :: order_ = 4
      integer :: cells_ = 20
      double precision :: x_min_ = 0d0, x_max_ = 1d0
    end type

    associate (args => get_args ())
      associate (result => compute (args%order_, args%cells_))
        print *, result
      end associate
    end associate

  contains

    function get_args () result (r)
      type(args_t) :: r
      r%order_ = 2
      r%cells_ = 10
    end function

    function compute (order, cells) result (r)
      integer, intent(in) :: order, cells
      integer :: r
      r = order * cells
    end function

  end program

  $ gfortran associate_infer_program_type.f90

  gfortran rejects args%order_ and args%cells_ with
  "Expected argument list".  The program should compile
  and run cleanly.
Comment 1 GCC Commits 2026-06-06 17:11:58 UTC
The master branch has been updated by Jerry DeLisle <jvdelisle@gcc.gnu.org>:

https://gcc.gnu.org/g:418c6b5fbab2b3bf5e7727657172864ae5440c1d

commit r17-1394-g418c6b5fbab2b3bf5e7727657172864ae5440c1d
Author: Jerry DeLisle <jvdelisle@gcc.gnu.org>
Date:   Sat Jun 6 09:47:59 2026 -0700

    fortran: inferred-type ASSOCIATE name giving spurious "Expected argument list"
    
    In gfc_match_varspec, when parsing component references on an
    inferred-type ASSOCIATE name, the parser incorrectly matched the
    component name as a type-bound procedure .
    
    For inferred-type ASSOCIATE names the parse-time candidate type may
    differ from the final resolved type.  If gfc_find_component fails with the
    default access check, retry with noaccess=true; the resolution pass
    will substitute the correct type.
    
    Assisted by: Claude Sonnet 4.6
    
            PR fortran/125531
    
    gcc/fortran/ChangeLog:
    
            * primary.cc (gfc_match_varspec): Before erroring on a zero-argument
            COMPCALL, check for a same-named data component and fall back to the
            data-component path.  For inferred-type ASSOCIATE names, retry
            gfc_find_component with noaccess=true when the normal search fails.
    
    gcc/testsuite/ChangeLog:
    
            * gfortran.dg/associate_infer_program_type.f90: New test.
Comment 2 GCC Commits 2026-06-15 16:30:54 UTC
The releases/gcc-16 branch has been updated by Jerry DeLisle <jvdelisle@gcc.gnu.org>:

https://gcc.gnu.org/g:1386faee4600160c9a0f85f683d6c1c65d282099

commit r16-9104-g1386faee4600160c9a0f85f683d6c1c65d282099
Author: Jerry DeLisle <jvdelisle@gcc.gnu.org>
Date:   Sat Jun 6 09:47:59 2026 -0700

    fortran: inferred-type ASSOCIATE name giving spurious "Expected argument list"
    
    In gfc_match_varspec, when parsing component references on an
    inferred-type ASSOCIATE name, the parser incorrectly matched the
    component name as a type-bound procedure .
    
    For inferred-type ASSOCIATE names the parse-time candidate type may
    differ from the final resolved type.  If gfc_find_component fails with the
    default access check, retry with noaccess=true; the resolution pass
    will substitute the correct type.
    
    Assisted-by: Claude Sonnet 4.6
    
            PR fortran/125531
    
    gcc/fortran/ChangeLog:
    
            * primary.cc (gfc_match_varspec): Before erroring on a zero-argument
            COMPCALL, check for a same-named data component and fall back to the
            data-component path.  For inferred-type ASSOCIATE names, retry
            gfc_find_component with noaccess=true when the normal search fails.
    
    gcc/testsuite/ChangeLog:
    
            * gfortran.dg/associate_infer_program_type.f90: New test.
    
    (cherry picked from commit 1572da928e4f067cb45c511156899bda1d73e593)
Comment 3 Jerry DeLisle 2026-06-21 02:49:15 UTC
Fixed and closing