gfc_namespace *module_ns;
gfc_interface *old_interface_head, *interface;
- if (gfc_state_stack->state != COMP_INTERFACE
+ if ((gfc_state_stack->state != COMP_INTERFACE
+ && gfc_state_stack->state != COMP_CONTAINS)
|| gfc_state_stack->previous == NULL
|| current_interface.type == INTERFACE_NAMELESS
|| current_interface.type == INTERFACE_ABSTRACT)
/* Variable not assignable from a PURE procedure but appears in
variable definition context. */
+ own_scope = own_scope
+ || (sym->attr.result && sym->ns->proc_name
+ && sym == sym->ns->proc_name->result);
if (!pointer && !own_scope && gfc_pure (NULL) && gfc_impure_variable (sym))
{
if (context)
/* Check for F08:C465. */
if ((!proc->attr.subroutine && !proc->attr.function)
|| (proc->attr.proc != PROC_MODULE
- && proc->attr.if_source != IFSRC_IFBODY)
+ && proc->attr.if_source != IFSRC_IFBODY
+ && !proc->attr.module_procedure)
|| proc->attr.abstract)
{
gfc_error ("%qs must be a module procedure or an external "
--- /dev/null
+! { dg-do compile }
+!
+! Test the fix for the testcase in comment 23 of PR96320, which used to
+! fail with the message: Variable ‘new_foo’ cannot appear in a variable
+! definition context.
+!
+! Contributed by Damian Rouson <damian@sourceryinstitute.org>
+!
+module foobar
+ implicit none
+
+ type foo
+ integer bar
+ end type
+
+ interface
+ pure module function create() result(new_foo)
+ implicit none
+ type(foo) new_foo
+ end function
+ end interface
+
+contains
+ module procedure create
+ new_foo%bar = 1 ! Error here
+ end procedure
+end module
+
+ use foobar
+ print *, create ()
+end
--- /dev/null
+! { dg-do run }
+!
+! Test the fix for the testcase in comment 24 of PR96320, which used to
+! fail with the message: ‘set_user_defined’ must be a module procedure or
+! an external procedure with an explicit interface at (1)
+!
+! Contributed by Damian Rouson <damian@sourceryinstitute.org>
+!
+module hole_interface
+ type hole_t
+ integer :: user_defined
+ real :: hole_diameter
+ contains
+ procedure set_user_defined
+ procedure set_diameter
+ end type
+
+ interface
+ module subroutine set_diameter (this, diameter)
+ class(hole_t) :: this
+ real :: diameter
+ end subroutine
+
+ module subroutine set_user_defined(this, user_defined)
+ class(hole_t) :: this
+ integer :: user_defined
+ end subroutine
+ end interface
+
+contains
+ module procedure set_user_defined
+ this%user_defined = user_defined
+ end procedure
+
+ module procedure set_diameter
+ this%hole_diameter = diameter
+ if (this%user_defined .lt. 0) then
+ call this%set_user_defined (0)
+ end if
+ end procedure
+end module
+
+ use hole_interface ! Error was here
+ type (hole_t) :: ht = hole_t (-1, 0.0)
+ call ht%set_diameter(1.0)
+ if ((ht%user_defined .ne. 0) .and. (ht%hole_diameter .ne. 1.0)) stop 1
+ call ht%set_user_defined (5)
+ if ((ht%user_defined .ne. 5) .and. (ht%hole_diameter .ne. 1.0)) stop 2
+ call ht%set_diameter(2.0)
+ if ((ht%user_defined .ne. 5) .and. (ht%hole_diameter .ne. 2.0)) stop 3
+end