ProtoDef-io / node-protodef

Describe your protocol, and read it with ease.
MIT License
30 stars 20 forks source link

`anon` compiler regression #156

Open Saiv46 opened 2 weeks ago

Saiv46 commented 2 weeks ago

anon type only works for directly defined containers. Also it probably should work with other types besides container/bitfield (like ({ a, ...null, b })).

/home/alexander/MEGA/Projects/github:Saiv46/nut-parser/node_modules/.pnpm/protodef@1.15.0/node_modules/protodef/src/datatypes/compiler-structures.js:231
        throw new Error('Cannot inline anonymous type: ' + type)
        ^

Error: Cannot inline anonymous type: closure
    at containerInlining (/home/alexander/MEGA/Projects/github:Saiv46/nut-parser/node_modules/.pnpm/protodef@1.15.0/node_modules/protodef/src/datatypes/compiler-structures.js:231:15)
    at module.exports.SizeOf.container (/home/alexander/MEGA/Projects/github:Saiv46/nut-parser/node_modules/.pnpm/protodef@1.15.0/node_modules/protodef/src/datatypes/compiler-structures.js:138:16)
    at SizeOfCompiler.compileType (/home/alexander/MEGA/Projects/github:Saiv46/nut-parser/node_modules/.pnpm/protodef@1.15.0/node_modules/protodef/src/compiler.js:397:90)
    at SizeOfCompiler.generate (/home/alexander/MEGA/Projects/github:Saiv46/nut-parser/node_modules/.pnpm/protodef@1.15.0/node_modules/protodef/src/compiler.js:235:34)
    at ProtoDefCompiler.compileProtoDefSync (/home/alexander/MEGA/Projects/github:Saiv46/nut-parser/node_modules/.pnpm/protodef@1.15.0/node_modules/protodef/src/compiler.js:42:44)
    at Object.<anonymous> (/home/alexander/MEGA/Projects/github:Saiv46/nut-parser/protodef.js:52:27)
    at Module._compile (node:internal/modules/cjs/loader:1434:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1518:10)
    at Module.load (node:internal/modules/cjs/loader:1249:32)
    at Module._load (node:internal/modules/cjs/loader:1065:12)

Node.js v22.2.0

Protocol definition to reproduce:

{
  "types": {
    "void": "native",
    "container": "native"
  },
  "sqirrel": {
    "types": {
      "closure": [
        "container",
        [
          {
            "name": "main",
            "type": "void"
          }
        ]
      ],
      "script": [
        "container",
        [
          {
            "anon": true,
            "type": "closure"
          }
        ]
      ]
    }
  }
}
Saiv46 commented 2 weeks ago

Documented in ProtoDef-io/ProtoDef#53