kaitai-io / kaitai_struct

Kaitai Struct: declarative language to generate binary data parsers in C++ / C# / Go / Java / JavaScript / Lua / Nim / Perl / PHP / Python / Ruby
https://kaitai.io
4.04k stars 199 forks source link

Invalid Java code generated: Switch selectors cannot be of type "long" #1100

Closed Gamebuster19901 closed 8 months ago

Gamebuster19901 commented 8 months ago

Problem

Kaitai generates switch statements where the selector expression is of type long. This is a violation of the Java SE Specification (§:14.1.1) which states that

switch blocks are not designed to work with the types boolean, long, float, and double. The selector expression of a switch statement or switch expression can not have one of these types.

Impact

Example

.ksy file (lines 43-44 and 62-65): https://github.com/TheGameCommunity/ExciteModder/blob/dda55f7e5ce7970467caf79feee2c0306ac3ac73/src/main/resources/kaitai/monster_res.ksy#L62-L65

generated code (lines 129 and 158 only): https://github.com/TheGameCommunity/ExciteModder/blob/dda55f7e5ce7970467caf79feee2c0306ac3ac73/build/generated/kaitai/com/gamebuster19901/excite/modding/game/file/kaitai/ResMonster.java#L129-L158

Build Error:

> Task :compileJava FAILED
/home/runner/work/ExciteModder/ExciteModder/build/generated/kaitai/com/gamebuster19901/excite/modding/game/file/kaitai/ResMonster.java:158: error: selector type long is not allowed
            switch (_root().header().compressed()) {
                   ^
generalmimon commented 8 months ago

Duplicate of #599