<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/126797>126797</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [Flang] Incorrect diagnostic due to private generic name still visible outside of the module.
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            flang:frontend
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          DanielCChen
      </td>
    </tr>
</table>

<pre>
    Consider the following code:
```
module m
   type base
      character(3) :: c = 'xxx'
      contains
         procedure, pass :: write => writeb
 generic, private :: write(unformatted) => write  !! generic write(unformated) is private, so it should not 
 !! be accessible outside of the module
   end type

 interface
      subroutine writeb (dtv, unit, iostat, iomsg)
 import base
         class(base), intent(in) :: dtv
         integer, intent(in) :: unit
         integer, intent(out) :: iostat
 character(*), intent(inout) :: iomsg
      end subroutine
   end interface

   contains
      subroutine mywrite( dtv, iostat, iomsg )
 class(base), intent(in) :: dtv
         integer, intent(out) :: iostat
         character(*), intent(inout) :: iomsg

         write ( 1, iostat = iostat, iomsg = iomsg ) dtv
         if (iostat .ne. 0) error stop 1
      end subroutine
end module

program resolve005a
   use m
 class(base), allocatable  :: b1
   integer :: stat
   character(200) :: msg

   allocate ( b1, source = base('abc') )
   open ( 1, file = 'resolve005a.1', form='unformatted', access='sequential' )

   call mywrite ( b1, stat, msg)

   deallocate(b1)
   close ( 1, status ='delete')

end program

subroutine writeb (dtv, unit, iostat, iomsg)
   use m, only: base
   class(base), intent(in) :: dtv
   integer, intent(in) :: unit
 integer, intent(out) :: iostat
   character(*), intent(inout) :: iomsg

 interface write(unformatted).                              !! This declaration should be allowed.
      subroutine writebaseext (dtv, unit, iostat, iomsg)
         import base
         class(base), intent(in) :: dtv
         integer, intent(in) :: unit
         integer, intent(out) :: iostat
         character(*), intent(inout) :: iomsg
      end subroutine
 end interface

   write (unit, iostat=iostat, iomsg=iomsg)    dtv
   if (iostat .ne. 0) error stop 2

end subroutine

subroutine writebaseext (dtv, unit, iostat, iomsg)
   use m, only: base
   class(base), intent(in) :: dtv
   integer, intent(in) :: unit
   integer, intent(out) :: iostat
 character(*), intent(inout) :: iomsg

   select type ( dtv )
      type is (base)
         write (unit, iostat=iostat, iomsg=iomsg)        dtv%c
 if (iostat .ne. 0) error stop 3
   end select
end subroutine
```

The test case in intentionally testing when a generic name is private, it should be allowed to declare another interface outside of the module.
Flang is currently issue an error as
```
error: Semantic errors in t1.f
./t1.f:54:18: error: Derived type 'base' has conflicting type-bound input/output procedure 'write(unformatted)'
        subroutine writebaseext (dtv, unit, iostat, iomsg)
                   ^^^^^^^^^^^^
./t1.f:10:18: Procedure 'write' of type 'base' is bound to 'writeb'
        subroutine writeb (dtv, unit, iostat, iomsg)
                   ^^^^^^

```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzUV91u4zoOfhrlhpjAlus6uciFt50Ae7fAzgvIMhNroUhZSc60b39AWf5Jmk5PZwbn4BQFkkgkRX4kP0rCe3U0iDtW_ouVzyvRh8663bMwCvXTU4dm1dj2dfdkjVctOggdwsFqbb8rcwRpW2RFzbKaPWbpP6tPtu01wollNQCE1zNCIzwOPwFAdsIJGdAxvikY3wKZKGqQwIpnYLx6eXlhvJrlrQlCGT8tAMDZWYlt75DxJzgL70cj350KSIZY8XX40ZDeEQ06JaO0UxcRZWYFxje9OVh3EiFgO_g0WwBgPGc8H6280RlUlB9t0zHeggrgO9vrFowNQG4kOw2CkBK9V41GsH0gcMEeIrwDfEOwaNoIICGc1aBMQHcQcsbS942zfVAGU7DA-KYNF_KgNyrQp7I-iPTt5I-Mb6Ot09m6cJ0ZAlsL7xnfxHW-jVomoAmMb5RZZIsOWeiR0JFS-p589OYDBduHhUbyO6uvKobx-q1ft4oU5ngWYTjDNOO6BHNYfVNoC3RPr2PSIcF7AyskXH8ngO_hMSXr53BZmkj9wjeQz0HFRnwTX1xLkb7x_kA2kvba4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