Skip to content

Commit 523537f

Browse files
authored
[flang] Silence spurious error (#128777)
When checking for conflicts between type-bound generic defined I/O procedures and non-type-bound defined I/O generic interfaces, don't worry about conflicts where the type-bound generic interface is inaccessible in the scope around the non-type-bound interface. Fixes #126797.
1 parent 8b7a90b commit 523537f

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

flang/lib/Semantics/check-declarations.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3398,11 +3398,12 @@ void CheckHelper::CheckAlreadySeenDefinedIo(const DerivedTypeSpec &derivedType,
33983398
return;
33993399
}
34003400
if (const Scope * dtScope{derivedType.scope()}) {
3401-
if (auto iter{dtScope->find(generic.name())}; iter != dtScope->end()) {
3401+
if (auto iter{dtScope->find(generic.name())}; iter != dtScope->end() &&
3402+
IsAccessible(*iter->second, generic.owner())) {
34023403
for (auto specRef : iter->second->get<GenericDetails>().specificProcs()) {
34033404
const Symbol &specific{specRef->get<ProcBindingDetails>().symbol()};
3404-
if (specific == proc) { // unambiguous, accept
3405-
continue;
3405+
if (specific == proc) {
3406+
continue; // unambiguous, accept
34063407
}
34073408
if (const auto *specDT{GetDtvArgDerivedType(specific)};
34083409
specDT && evaluate::AreSameDerivedType(derivedType, *specDT)) {

flang/test/Semantics/io11.f90

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,3 +689,34 @@ module m26b
689689
procedure unformattedRead
690690
end interface
691691
end
692+
693+
module m27a
694+
type t
695+
integer c
696+
contains
697+
procedure ur1
698+
generic, private :: read(unformatted) => ur1
699+
end type
700+
contains
701+
subroutine ur1(dtv,unit,iostat,iomsg)
702+
class(t),intent(inout) :: dtv
703+
integer,intent(in) :: unit
704+
integer,intent(out) :: iostat
705+
character(*),intent(inout) :: iomsg
706+
read(unit,iotype,iostat=iostat,iomsg=iomsg) dtv%c
707+
end
708+
end
709+
module m27b
710+
use m27a
711+
interface read(unformatted)
712+
module procedure ur2 ! ok, t's generic is inaccessible
713+
end interface
714+
contains
715+
subroutine ur2(dtv,unit,iostat,iomsg)
716+
class(t),intent(inout) :: dtv
717+
integer,intent(in) :: unit
718+
integer,intent(out) :: iostat
719+
character(*),intent(inout) :: iomsg
720+
read(unit,iotype,iostat=iostat,iomsg=iomsg) dtv%c
721+
end
722+
end

0 commit comments

Comments
 (0)