http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42769

--- Comment #34 from Mikael Morin <mikael at gcc dot gnu.org> 2011-03-01 
16:26:53 UTC ---
The hack in comment 32 compiles correctly comment 24, but rejects the following
variant (with the type-bound call in a subroutine) with:

  use mod2
          1
Error: Name 'my_get' at (1) is an ambiguous reference to 'my_get' from module
'mod2'



module mod1
  type :: t1
  contains
    procedure, nopass :: get => my_get
  end type
contains 
  subroutine my_get()
    print *,"my_get (mod1)"
  end subroutine
end module

module mod2
contains 
  subroutine my_get()    ! must have the same name as the function in mod1
    print *,"my_get (mod2)"
  end subroutine
end module

  use mod2
  use mod1        ! order of use statements is important
  type(t1) :: a
  call call_get
  contains
  subroutine call_get
    call a%get()
  end subroutine call_get
end


The reason is that the following code in resolve_call reloads the procedure
symbol from the current namespace. This could be disabled with a flag, but it
would just make the hack uglier.

  if (csym && gfc_current_ns->parent && csym->ns != gfc_current_ns)
    {
      gfc_symtree *st;
      gfc_find_sym_tree (csym->name, gfc_current_ns, 1, &st);
      sym = st ? st->n.sym : NULL;
      if (sym && csym != sym
          && sym->ns == gfc_current_ns
          && sym->attr.flavor == FL_PROCEDURE
          && sym->attr.contained)
    {
      sym->refs++;
      if (csym->attr.generic)
        c->symtree->n.sym = sym;
      else
        c->symtree = st;
      csym = c->symtree->n.sym;
    }
    }

Reply via email to