Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

incomplete bitwise transpilation #673

Closed
fperrad opened this issue Jul 8, 2023 · 4 comments
Closed

incomplete bitwise transpilation #673

fperrad opened this issue Jul 8, 2023 · 4 comments
Labels
bug Something isn't working

Comments

@fperrad
Copy link
Contributor

fperrad commented Jul 8, 2023

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
Copy link
Member

@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 hishamhm added the bug Something isn't working label Jul 10, 2023
@hishamhm
Copy link
Member

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
Copy link
Contributor Author

fperrad commented Jul 20, 2023

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

hishamhm added a commit that referenced this issue Jul 21, 2023
@hishamhm
Copy link
Member

@fperrad yes, it covers // as well!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants