Hello Developers!
In the coming days we will begin rolling out improvements regarding binary and hexadecimal integer literal parsing rules. In some cases this could affect your experience. To help with this we have a rollout that involves multiple stages of in studio warnings as well outreach to developers affected.
Please take a moment to read over these changes and feel free to ask questions or provide feedback.
Overview:
The logic that was used to parse binary and hexadecimal integer literals resulted in some literals not being expressed as intended by the developer. They were able to be formatted in a way that doesnβt produce the number you might intend and, in some cases, allows for syntax that is invalid in the original Lua language.
With that in mind, here are three issues that are being addressed.
Silent Hexadecimal Integer Literal Overflow
Luau parses hexadecimal and binary literals as 64-bit integers before converting them to Luau numbers.
As a result, numbers that exceed 2^64 are silently truncated to 2^64, this can result in unexpected program behavior.
Going forward, there will be a linter warning in Script Analysis to notify you about places where such truncation is happening. For example:
-- Hexadecimal number literal exceeded available precision and has been truncated to 2^64
local x = 0x11111111111111111111111111111111111AA
-- The line above results in the same number as this:
local x = 0xffffffffffffffff
For some context, Lua 5.1 would have been parsed this as 2.3787461545099e+43 or 4294967295 (0xffffffff), depending on the C compiler version. In Lua 5.3, the last 16 hexadecimal digits are taken into account which results in 1229782938247303594 (0x11111111111111AA).
Looking ahead, we can revisit how parsing of large integers are performed and if there is a need to implement hex floats.For now itβs important for us to report code that does not behave as might be expected.
Silent binary integer literal overflow
The same issue happens with binary integer literals and a new linter warning will be generated as well. For example:
-- Binary number literal exceeded available precision and has been truncated to 2^64
local x = 0b11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
-- The line above results in the same number as this:
local x = 0b1111111111111111111111111111111111111111111111111111111111111111
Double β0xβ prefix
It was possible to make a mistake and write β0xβ two times in front of a hexadecimal integer literal:
-- Hexadecimal number literal has a double prefix, which will fail to parse in the future; remove the extra 0x to fix
local a = 0x0x20
-- Same as
local a = 0x20
Rollout
For binary and hexadecimal integer literal overflow, we plan to enable the linter warnings this week and keep it enabled for the foreseeable future.
We will be reaching out to specific experience developers to make the fix. Please keep an eye out for communications from us if you are seeing linter warnings.
Once we are sure that experiences on the platform are fixed, we will revisit this and consider changing it to a parsing error.
For double hexadecimal integer literal prefix, we have a stricter plan:
Starting this week, Studio will generate a lint warning for double hexadecimal integer literal prefix. We will reach out to developers that have been affected by this.
On September 19, 2022, this will become a hard parsing error in Studio and script with an error will not run. Then October 19, 2022, this will become a hard parsing error on Client and Server as well.
Please let us know if you have any questions or concerns.
Thanks!
EDIT: we have relaxed the timeline to give developers more time to apply required changes.