kaitai_struct
kaitai_struct copied to clipboard
`parent` key is not an actually is expression
Analysing code when working on my own implementation of the compiler, I found that the parent
key is extracted as an expression, but actually the only possible expressions are:
-
false
-
_parent
-
_root
-
_root._parent
-
_root._parent._parent
- ...
That expressions although by the form looks acceptable, is rejected by the compiler:
-
param
where
Error:params: - id: param type: struct
io.kaitai.struct.precompile.TypeMismatchError: parent=Name(identifier(param)) is expected to be either of user type or
false
, but CalcKaitaiStructType found -
true ? _root : _parent
Error:io.kaitai.struct.precompile.TypeMismatchError: parent=IfExp(Bool(true),Name(identifier(_root)),Name(identifier(_parent))) is expected to be either of user type or
false
, but CalcKaitaiStructType found -
[_root, _parent][1]
Error:io.kaitai.struct.precompile.TypeMismatchError: parent=Subscript(List(WrappedArray(Name(identifier(_root)), Name(identifier(_parent)))),IntNum(1)) is expected to be either of user type or
false
, but CalcKaitaiStructType found
This is happened because:
-
parent
should have type of theUserType
- the type of all that expressions is inferred as
CalcKaitaiStructType
- the
UserType extends StructType
and theCalcKaitaiStructType extends StructType
, so they does not have the common ancestor
If parent
should be a true expression, than this looks like a bug. If parent
should only allow the currently allowed usage variants, it is better to rewrite it's parsing to be more straightforward.
What the desired behaviour?