vsariola / pakettic

TIC-80 cartridge packer
MIT License
19 stars 4 forks source link

Crash on code which compares for (in)equality with `nil` #6

Closed koorogi closed 1 year ago

koorogi commented 1 year ago

Input test file:

if a==nil then end
Traceback (most recent call last):                                                                                                                                                                                                                                                                                                                                         File "/home/koorogi/.local/bin/pakettic", line 8, in <module>
    sys.exit(main())
  File "/home/koorogi/.local/lib/python3.10/site-packages/pakettic/main.py", line 192, in main
    root = optimize.dlas(root, steps=args.steps, cost_func=_cost_func,
  File "/home/koorogi/.local/lib/python3.10/site-packages/pakettic/optimize.py", line 269, in dlas
    current_cost = cost_func(state, inf)
  File "/home/koorogi/.local/lib/python3.10/site-packages/pakettic/main.py", line 173, in _cost_func
    bytes = printer.format(root).encode("ascii")
  File "/home/koorogi/.local/lib/python3.10/site-packages/pakettic/printer.py", line 11, in format
    return Formatter(pretty=pretty).format(node)
  File "/home/koorogi/.local/lib/python3.10/site-packages/pakettic/printer.py", line 34, in format
    return ''.join(self.__addspaces(tokens))
  File "/home/koorogi/.local/lib/python3.10/site-packages/pakettic/printer.py", line 50, in __addspaces
    for token in tokens:
  File "/home/koorogi/.local/lib/python3.10/site-packages/pakettic/printer.py", line 420, in _
    yield from self.__traverse(node.block)
  File "/home/koorogi/.local/lib/python3.10/site-packages/pakettic/printer.py", line 63, in _
    yield from self.__traverse(n)
  File "/home/koorogi/.local/lib/python3.10/site-packages/pakettic/printer.py", line 324, in _
    yield from self.__traverse(node.test)
  File "/home/koorogi/.local/lib/python3.10/site-packages/pakettic/printer.py", line 381, in _
    if node.right.precedence >= node.precedence:
TypeError: '>=' not supported between instances of 'property' and 'int'

Similar crash when changing the code to check a~=nil

vsariola commented 1 year ago

Yeah, nils were not parsed correctly. Oops! Fixed. Thanks for the bug report! Will be part of next release; meanwhile, you can use

$ pip install git+https://github.com/vsariola/pakettic.git@main