diff --git a/shared/src/main/scala/io/kaitai/struct/format/ClassSpec.scala b/shared/src/main/scala/io/kaitai/struct/format/ClassSpec.scala index 580c37dd7..f76559e9f 100644 --- a/shared/src/main/scala/io/kaitai/struct/format/ClassSpec.scala +++ b/shared/src/main/scala/io/kaitai/struct/format/ClassSpec.scala @@ -78,6 +78,14 @@ case class ClassSpec( def parentType: DataType = parentClass.toDataType + /** + * Determines whether this `ClassSpec` represents a type that is external + * (i.e. not defined in the same .ksy file) from the perspective of the given + * `ClassSpec`. + */ + def isExternal(curClass: ClassSpec): Boolean = + name.head != curClass.name.head + /** * Recursively traverses tree of types starting from this type, calling * certain function for every type, starting from this one. diff --git a/shared/src/main/scala/io/kaitai/struct/precompile/ParentTypes.scala b/shared/src/main/scala/io/kaitai/struct/precompile/ParentTypes.scala index 288267786..c6c002352 100644 --- a/shared/src/main/scala/io/kaitai/struct/precompile/ParentTypes.scala +++ b/shared/src/main/scala/io/kaitai/struct/precompile/ParentTypes.scala @@ -68,7 +68,6 @@ class ParentTypes(classSpecs: ClassSpecs) { } def markupParentAs(curClass: ClassSpec, ut: UserType): Unit = { - Log.typeProcParent.info(() => s"..... class=$ut has parent=${curClass.nameAsStr}") ut.classSpec match { case Some(usedClass) => markupParentAs(curClass, usedClass) @@ -79,6 +78,10 @@ class ParentTypes(classSpecs: ClassSpecs) { } def markupParentAs(parent: ClassSpec, child: ClassSpec): Unit = { + // Don't allow type usages across spec boundaries to affect parent resolution + if (child.isExternal(parent)) + return + Log.typeProcParent.info(() => s"..... class=${child.nameAsStr} has parent=${parent.nameAsStr}") child.parentClass match { case UnknownClassSpec => child.parentClass = parent