teal-language / tl

The compiler for Teal, a typed dialect of Lua
MIT License
2.03k stars 101 forks source link

incomplete bitwise transpilation #673

Closed fperrad closed 11 months ago

fperrad commented 1 year ago

I try to transpile a Lua 5.3 module (see https://framagit.org/fperrad/lua-mqtt/-/blob/transpile/src/mqtt311.lua) with the following command:

tl gen --gen-target=5.1 --gen-compat=required -o src5.1/mqtt311.lua src/mqtt311.lua

Most of the bitwise operators are transpiled to bit32 calls, except in 3 lines. see commit https://framagit.org/fperrad/lua-mqtt/-/commit/d97093dcd38cf18c558d822f45062a2efed65ac5

note:

$ tl --version
0.15.2
$ lua -v
Lua 5.4.6  Copyright (C) 1994-2023 Lua.org, PUC-Rio
hishamhm commented 12 months ago

@fperrad Thanks for the report! At first glance, I think this is due to the lack of type information (that is, it wouldn't happen on a .tl file with type annotations in function arguments/variables)... Teal needs type info to know whether to output bit32 compat or metamethod compat calls. It still shouldn't generate invalid operators when outputting Lua 5.1 code, though. I'll need to investigate this further!

hishamhm commented 11 months ago

Fixed! Now it no longer outputs 5.3 operators with --gen-target=5.1, even if variable types can't be determined. I tested it with your mqtt311.lua and also added a smaller regression test.

fperrad commented 11 months ago

My issue was about bitwise operators. Does your fix include too the floor division operator // ?

hishamhm commented 11 months ago

@fperrad yes, it covers // as well!