diff --git a/flang/lib/Semantics/tools.cpp b/flang/lib/Semantics/tools.cpp --- a/flang/lib/Semantics/tools.cpp +++ b/flang/lib/Semantics/tools.cpp @@ -103,9 +103,12 @@ if (!lhsType || !rhsType) { return Tristate::No; // error or rhs is untyped } - if (lhsType->IsUnlimitedPolymorphic() || rhsType->IsUnlimitedPolymorphic()) { + if (lhsType->IsUnlimitedPolymorphic()) { return Tristate::No; } + if (rhsType->IsUnlimitedPolymorphic()) { + return Tristate::Maybe; + } TypeCategory lhsCat{lhsType->category()}; TypeCategory rhsCat{rhsType->category()}; if (rhsRank > 0 && lhsRank != rhsRank) { diff --git a/flang/test/Semantics/defined-ops.f90 b/flang/test/Semantics/defined-ops.f90 --- a/flang/test/Semantics/defined-ops.f90 +++ b/flang/test/Semantics/defined-ops.f90 @@ -69,6 +69,10 @@ class(t), intent(out) :: x integer, intent(in) :: y end + subroutine s2(x, y) + real, intent(out) :: x + class(*), intent(in) :: y + end end interface interface operator(+) integer function f(x, y) @@ -77,12 +81,15 @@ end end interface contains - subroutine test(x, y) + subroutine test(x, y, z) class(t) :: x, y + class(*), intent(in) :: z + real :: a !CHECK: CALL s1(x,2_4) x = 2 !CHECK: i=f(x,y) i = x + y + !CHECK: CALL s2(a,z) + a = z end end -