fix >> (signed right shift) on Lua 5.3+ (#1720)#1721
Conversation
|
|
||
| exports[`Bitop [5.5] ("a>>b") 1`] = ` | ||
| "local ____exports = {} | ||
| ____exports.__result = (((a & 4294967295) ~ 2147483648) - 2147483648) // (1 << (b & 31)) |
There was a problem hiding this comment.
Not sure this amount of magic in the generated code is really explainable. I would be perfectly happy with fixing the wording on the diagnostic and telling people to use >>> (or their own function) instead - and mentioning it in the caveat docs.
There was a problem hiding this comment.
agreed, this was a demonstration of the "magic" approach. Reverting to option 2 with improved diagnostics
There was a problem hiding this comment.
Side note: a chunk of the apparent magic was the printer, not the values. In the source the constants were 0xFFFFFFFF (low 32 bits) and 0x80000000 (sign bit), readable in hex but opaque after lua.createNumericLiteral rendered them as decimal (4294967295, 2147483648).
Might be worth letting the emitter preserve the original radix for numeric literals. Not relevant for this PR, but in other cases where hex is the meaningful form it would keep generated code readable. Could file a separate issue for this?
Fixes #1720
alternatively, can improve diagnostic and let users provide their own functions, which is potentially less controversial and stays truer to the "pure transpile" story.
Separately, not directly relevant: