primary->value.compcall.actual = NULL;
else
{
+ /* Before erroring, check whether there is also a data
+ component with this name. Use noaccess=true so
+ that private components are also found. */
+ if (sym && gfc_find_component (sym, name, true, true, NULL))
+ {
+ /* Restore expr to EXPR_VARIABLE and let the data
+ component path below handle it. */
+ primary->expr_type = EXPR_VARIABLE;
+ gfc_free_actual_arglist (primary->value.compcall.actual);
+ primary->value.compcall.actual = NULL;
+ tbp = NULL;
+ goto try_data_component;
+ }
gfc_error ("Expected argument list at %C");
return MATCH_ERROR;
}
break;
}
+ try_data_component:
+
previous = component;
if (!inquiry && !intrinsic)
- component = gfc_find_component (sym, name, false, false, &tmp);
+ {
+ component = gfc_find_component (sym, name, false, false, &tmp);
+ /* For inferred-type ASSOCIATE names the parse-time candidate type
+ may not be the final type; a private component in the candidate
+ type may correspond to a public component in the correct type.
+ Accept it tentatively so that resolution can fix up the type. */
+ if (!component && !tbp
+ && primary->symtree && primary->symtree->n.sym->assoc
+ && primary->symtree->n.sym->assoc->inferred_type)
+ component = gfc_find_component (sym, name, true, false, &tmp);
+ }
else
component = NULL;
--- /dev/null
+! { dg-do compile }
+! { dg-options "" }
+!
+! PR fortran/125531
+! ASSOCIATE with a contained-function selector, using the result's data
+! components as arguments to another function (also from CONTAINS), where
+! the result type is defined in program scope. This used to fail with
+! "Invalid association target".
+!
+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