diff --git a/flang/lib/Evaluate/type.cpp b/flang/lib/Evaluate/type.cpp --- a/flang/lib/Evaluate/type.cpp +++ b/flang/lib/Evaluate/type.cpp @@ -209,7 +209,11 @@ static const semantics::Symbol *FindParentComponent( const semantics::DerivedTypeSpec &derived) { const semantics::Symbol &typeSymbol{derived.typeSymbol()}; - if (const semantics::Scope * scope{typeSymbol.scope()}) { + const semantics::Scope *scope{derived.scope()}; + if (!scope) { + scope = typeSymbol.scope(); + } + if (scope) { const auto &dtDetails{typeSymbol.get()}; if (auto extends{dtDetails.GetParentComponentName()}) { if (auto iter{scope->find(*extends)}; iter != scope->cend()) { diff --git a/flang/test/Fir/dispatch.f90 b/flang/test/Fir/dispatch.f90 --- a/flang/test/Fir/dispatch.f90 +++ b/flang/test/Fir/dispatch.f90 @@ -44,6 +44,16 @@ procedure :: a1_proc => a2_proc end type + type ty_kind(i, j) + integer, kind :: i, j + integer :: a(i) + end Type + + type, extends(ty_kind) :: ty_kind_ex + integer :: b(j) + end type + type(ty_kind(10,20)) :: tk1 + type(ty_kind_ex(10,20)) :: tke1 contains subroutine display1_p1(this) @@ -280,6 +290,9 @@ ! Check the layout of the binding table. This is easier to do in FIR than in ! LLVM IR. +! BT-LABEL: fir.dispatch_table @_QMdispatch1Tty_kindK10K20 +! BT-LABEL: fir.dispatch_table @_QMdispatch1Tty_kind_exK10K20 extends("_QMdispatch1Tty_kindK10K20") + ! BT-LABEL: fir.dispatch_table @_QMdispatch1Tp1 { ! BT: fir.dt_entry "aproc", @_QMdispatch1Paproc ! BT: fir.dt_entry "display1", @_QMdispatch1Pdisplay1_p1