Here is a buggy .ksy:
meta:
id: bug
file-extension: na
endian: le
seq:
- id: body
type: type_inner
# uncomment to fix bug
# - id: body2
# type: type_unused
types:
type_reused:
seq:
- id: count
type: s4
type_inner:
seq:
- id: file_name
type: type_reused
type_unused:
seq:
- id: source_code_loc
type: type_reused
The compile error is:
/home/kh4n/Documents/jt-loader/target/generated-sources/kaitai/name/kh4n/jtloader/Bug.java:[110,59] incompatible types: name.kh4n.jtloader.Bug.TypeUnused cannot be converted to name.kh4n.jtloader.Bug.TypeInner
It is caused because type_reused (generated as TypeReused) has its _parent set to Bug.TypeInner:
public TypeReused(KaitaiStream _io, Bug.TypeInner _parent, Bug _root) {
super(_io);
this._parent = _parent;
this._root = _root;
_read();
}
...
If you uncomment this becomes:
public TypeReused(KaitaiStream _io, KaitaiStruct _parent, Bug _root) {
super(_io);
this._parent = _parent;
this._root = _root;
_read();
}
as it should. Manually changing the generated file also works. Not a huge issue because you can just use the type somewhere, but worth mentioning nonetheless as it is pretty common to have a type defined and then used somewhere that is currently unreachable as you are prototyping, which can be very confusing to debug.
I think it might be caused by an optimization which notices that type_unused is unreachable so it makes type_reused's parent type_inner (the only place it is technically used) but then the type_unused code is still emitted. I don't know the code base but if someone points me to possible file(s) I can try to fix the issue :). I will try my best to solve it on my own.
Here is a buggy .ksy:
The compile error is:
It is caused because
type_reused(generated asTypeReused) has its_parentset toBug.TypeInner:If you uncomment this becomes:
as it should. Manually changing the generated file also works. Not a huge issue because you can just use the type somewhere, but worth mentioning nonetheless as it is pretty common to have a type defined and then used somewhere that is currently unreachable as you are prototyping, which can be very confusing to debug.
I think it might be caused by an optimization which notices that
type_unusedis unreachable so it makestype_reused's parenttype_inner(the only place it is technically used) but then thetype_unusedcode is still emitted. I don't know the code base but if someone points me to possible file(s) I can try to fix the issue :). I will try my best to solve it on my own.