gfc_expr *kind_expr;
gfc_component *c1, *c2;
match m;
+ gfc_symtree *s = NULL;
type_param_spec_list = NULL;
goto error_return;
}
+ /* If we are in an interface body, the instance will not have been imported.
+ Make sure that it is imported implicitly. */
+ s = gfc_find_symtree (gfc_current_ns->sym_root, pdt->name);
+ if (gfc_current_ns->proc_name
+ && gfc_current_ns->proc_name->attr.if_source == IFSRC_IFBODY
+ && s && s->import_only && pdt->attr.imported)
+ {
+ s = gfc_find_symtree (gfc_current_ns->sym_root, instance->name);
+ if (!s)
+ {
+ gfc_get_sym_tree (instance->name, gfc_current_ns, &s, false,
+ &gfc_current_locus);
+ s->n.sym = instance;
+ }
+ s->n.sym->attr.imported = 1;
+ s->import_only = 1;
+ }
+
m = MATCH_YES;
if (instance->attr.flavor == FL_DERIVED
- && instance->attr.pdt_type)
+ && instance->attr.pdt_type
+ && instance->components)
{
instance->refs++;
if (ext_param_list)
|| startswith (name, "__vtype_")))
p = name;
+ /* Include pdt_types if their associated pdt_template is in a
+ USE, ONLY list. */
+ if (p == NULL && name[0] == 'P'
+ && startswith (name, "Pdt")
+ && module_list)
+ {
+ gfc_use_list *ml = module_list;
+ for (; ml; ml = ml->next)
+ if (ml->rename
+ && !strncmp (&name[3], ml->rename->use_name,
+ strlen (ml->rename->use_name)))
+ p = name;
+ }
+
/* Skip symtree nodes not in an ONLY clause, unless there
is an existing symtree loaded from another USE statement. */
if (p == NULL)
--- /dev/null
+! { dg-do compile }
+!
+! Tests the fix for pr122670, where use only did not compile for PDTs. Also, it
+! was found in the course of developing the fix that import only did not work
+! either.
+!
+! Contributed by Damian Rouson <damian@archaeologic.codes>
+!
+module tensor_m
+ implicit none
+
+ type tensor_t(k)
+ integer, kind :: k = kind(0.)
+ real(k), allocatable :: value_
+ end type
+
+ interface
+ function myfunc (arg)
+ import tensor_t
+ implicit none
+ type (tensor_t) myfunc
+ type (tensor_t), intent(in) :: arg
+ end function
+ end interface
+
+contains
+ function y(x)
+ type(tensor_t) x, y
+ y = tensor_t(x%value_)
+ end function
+end module
+
+function myfunc (arg)
+ use tensor_m, only : tensor_t
+ implicit none
+ type (tensor_t) myfunc
+ type (tensor_t), intent(in) :: arg
+ myfunc = arg
+ myfunc%value_ = myfunc%value_ * 2.0
+end function
+
+ use tensor_m, only : tensor_t, y, myfunc
+ implicit none
+ type(tensor_t) desired_output
+ desired_output = y(tensor_t(42.))
+ desired_output = myfunc (desired_output)
+ print *, desired_output%value_
+end