diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp --- a/flang/lib/Semantics/resolve-names.cpp +++ b/flang/lib/Semantics/resolve-names.cpp @@ -2718,7 +2718,7 @@ const auto &useName{std::get<1>(x.t)}; AddUseRename(useName.source); SymbolRename rename{AddUse(localName.source, useName.source)}; - if (rename.use) { + if (rename.use && localName.source != useName.source) { EraseRenamedSymbol(*rename.use); } Resolve(useName, rename.use); diff --git a/flang/test/Semantics/resolve116.f90 b/flang/test/Semantics/resolve116.f90 new file mode 100644 --- /dev/null +++ b/flang/test/Semantics/resolve116.f90 @@ -0,0 +1,24 @@ +! RUN: %python %S/test_errors.py %s %flang_fc1 +! Test rename to the same name. +module m1 + integer, allocatable :: a(:) + + interface operator(.add.) + module procedure add + end interface + +contains + integer function add(a, b) + integer, intent(in) :: a, b + + add = a + b + end function +end + +program p1 + use m1, a => a, operator(.add.) => operator(.add.) + + allocate(a(10)) + deallocate(a) + print *, 2 .add. 2 +end