Skip to content

Commit d6f99c2

Browse files
committed
Stop checking _parent and _root of external types
Since #283, it's incorrect to assume that `_parent` should be `this` and `_root` should be `this._root` for external types. Instead, when crossing the .ksy spec boundary to an external type `obj`, `obj._root == obj` and `obj._parent == null` should hold, but we will not check that for now.
1 parent 25c873f commit d6f99c2

3 files changed

Lines changed: 9 additions & 8 deletions

File tree

shared/src/main/scala/io/kaitai/struct/languages/JavaCompiler.scala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,8 +1042,6 @@ class JavaCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig)
10421042
}
10431043

10441044
override def attrParentParamCheck(actualParentExpr: Ast.expr, ut: UserType, shouldDependOnIo: Option[Boolean], msg: String): Unit = {
1045-
if (ut.isOpaque)
1046-
return
10471045
/** @note Must be kept in sync with [[JavaCompiler.parseExpr]] */
10481046
val (expectedParent, dependsOnIo) = ut.forcedParent match {
10491047
case Some(USER_TYPE_NO_PARENT) => ("null", false)

shared/src/main/scala/io/kaitai/struct/languages/PythonCompiler.scala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -804,8 +804,6 @@ class PythonCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig)
804804
}
805805

806806
override def attrParentParamCheck(actualParentExpr: Ast.expr, ut: UserType, shouldDependOnIo: Option[Boolean], msg: String): Unit = {
807-
if (ut.isOpaque)
808-
return
809807
/** @note Must be kept in sync with [[PythonCompiler.parseExpr]] */
810808
val (expectedParent, dependsOnIo) = ut.forcedParent match {
811809
case Some(USER_TYPE_NO_PARENT) => ("None", false)

shared/src/main/scala/io/kaitai/struct/languages/components/GenericChecks.scala

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -390,12 +390,17 @@ trait GenericChecks extends LanguageCompiler with EveryReadIsExpression {
390390

391391
def attrUserTypeCheck(id: Identifier, utExpr: Ast.expr, ut: UserType, shouldDependOnIo: Option[Boolean]): Unit = {
392392
/** @note Must be kept in sync with [[JavaCompiler.parseExpr]] */
393-
if (!ut.isOpaque) {
393+
if (!ut.isExternal(typeProvider.nowClass)) {
394+
// TODO: perhaps it would make sense to enforce `obj._root == obj` and `obj._parent == null`
395+
// for non-opaque external types in the future, but for now we won't perform any checks on
396+
// external types
394397
attrUserTypeParamCheck(id, ut, utExpr, RootIdentifier, CalcKaitaiStructType(), Ast.expr.Name(Ast.identifier(Identifier.ROOT)), shouldDependOnIo)
398+
attrParentParamCheck(id, Ast.expr.Attribute(utExpr, Ast.identifier(Identifier.PARENT)), ut, shouldDependOnIo)
395399
}
396-
attrParentParamCheck(id, Ast.expr.Attribute(utExpr, Ast.identifier(Identifier.PARENT)), ut, shouldDependOnIo)
397-
(ut.classSpec.get.params, ut.args).zipped.foreach { (paramDef, argExpr) =>
398-
attrUserTypeParamCheck(id, ut, utExpr, paramDef.id, paramDef.dataType, argExpr, shouldDependOnIo)
400+
if (!ut.isOpaque) {
401+
(ut.classSpec.get.params, ut.args).zipped.foreach { (paramDef, argExpr) =>
402+
attrUserTypeParamCheck(id, ut, utExpr, paramDef.id, paramDef.dataType, argExpr, shouldDependOnIo)
403+
}
399404
}
400405
}
401406

0 commit comments

Comments
 (0)