@@ -836,6 +836,13 @@ Cppyy::TCppScope_t Cppyy::GetUnderlyingScope(TCppScope_t scope)
836836Cppyy::TCppScope_t Cppyy::GetScope (const std::string& name,
837837 TCppScope_t parent_scope)
838838{
839+ // CppInterOp directly looks at the AST which is not enough.
840+ // We require lazy module loading that ROOT relies on, so we do it here first.
841+ // Use TClass::GetClass to trigger auto-loading of dictionaries and
842+ // modules.
843+ if (!parent_scope || parent_scope == Cpp::GetGlobalScope ())
844+ TClass::GetClass (name.c_str (), true /* load */ , true /* silent */ );
845+
839846 if (Cppyy::TCppScope_t scope = Cpp::GetScope (name, parent_scope))
840847 return scope;
841848 if (!parent_scope || parent_scope == Cpp::GetGlobalScope ())
@@ -933,8 +940,16 @@ Cppyy::TCppScope_t Cppyy::GetActualClass(TCppScope_t klass, TCppObject_t obj) {
933940 std::string mangled_name = typ->name ();
934941 std::string demangled_name = Cpp::Demangle (mangled_name);
935942
936- if (TCppScope_t scope = Cppyy::GetScope (demangled_name))
937- return scope;
943+ if (TCppScope_t scope = Cppyy::GetScope (demangled_name)) {
944+ // Only return the derived type if it has a complete definition in the
945+ // interpreter. Internal classes like TCling have no public header and
946+ // no dictionary, so their CXXRecordDecl has no DefinitionData.
947+ // returning them crashes when querying bases/offsets. Fall back
948+ // to the declared base type instead (equivalent to a
949+ // clActual->GetClassInfo() guard).
950+ if (Cpp::IsComplete (scope))
951+ return scope;
952+ }
938953
939954 return klass;
940955}
@@ -1474,9 +1489,13 @@ bool Cppyy::GetSmartPtrInfo(
14741489// type offsets --------------------------------------------------------------
14751490ptrdiff_t Cppyy::GetBaseOffset (TCppScope_t derived, TCppScope_t base,
14761491 TCppObject_t address, int direction, bool rerror)
1477- {
1492+ {
1493+ // Either base or derived class is incomplete, treat silently
1494+ if (!Cpp::IsComplete (derived) || !Cpp::IsComplete (base))
1495+ return rerror ? (ptrdiff_t )-1 : 0 ;
1496+
14781497 intptr_t offset = Cpp::GetBaseClassOffset (derived, base);
1479-
1498+
14801499 if (offset == -1 ) // Cling error, treat silently
14811500 return rerror ? (ptrdiff_t )offset : 0 ;
14821501
0 commit comments