diff --git a/flang/lib/Semantics/expression.cpp b/flang/lib/Semantics/expression.cpp --- a/flang/lib/Semantics/expression.cpp +++ b/flang/lib/Semantics/expression.cpp @@ -2946,6 +2946,9 @@ } } if (proc) { + if (const auto *binding{proc->detailsIf()}) { + proc = &binding->symbol(); + } ActualArguments actualsCopy{actuals_}; actualsCopy[1]->Parenthesize(); return ProcedureRef{ProcedureDesignator{*proc}, std::move(actualsCopy)}; diff --git a/flang/test/Parser/defined-ops.f90 b/flang/test/Parser/defined-ops.f90 new file mode 100644 --- /dev/null +++ b/flang/test/Parser/defined-ops.f90 @@ -0,0 +1,29 @@ +! RUN: %f18 -funparse %s 2>&1 | FileCheck %s + +! Check that the analyzed form of a type-bound defined operator or assignment +! uses the resolved subprogram. + +module m + type :: t + contains + procedure :: assign + procedure :: add + generic :: assignment(=) => assign + generic :: operator(+) => add + end type +contains + subroutine assign(x, y) + class(t), intent(out) :: x + class(t), intent(in) :: y + end + type(t) pure function add(x, y) + class(t), intent(in) :: x + integer, intent(in) :: y + end +end + +use m +type(t) :: x, y +!CHECK: CALL assign(x,add(y,1_4)) +x = y + 1 +end