kaitai_struct icon indicating copy to clipboard operation
kaitai_struct copied to clipboard

`parent` key is not an actually is expression

Open Mingun opened this issue 2 years ago • 0 comments

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
    params:
      - id: param
        type: struct
    
    Error:

    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 the UserType
  • the type of all that expressions is inferred as CalcKaitaiStructType
  • the UserType extends StructType and the CalcKaitaiStructType 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?

Mingun avatar Nov 28 '21 20:11 Mingun