So after browsing the source a bit more I found that even if you type out huge
constant decimal value lexer won't report the error (or your LSP).
And the reason is that even if overflow happens when lexer tries to convert
that string to actual integer value the function will just return NULL.
And Lua will automatically try to convert this value to 'lua_Number' (floating point)
instead of reporting overflow.
I think this is just plain wrong, it is fine to try to convert the same value to floating
point but only in case there is no overflow.
I would recommend that functions 'l_str2int' and 'luaO_str2num' start accepting additional
integer pointer as overflow flag.
This way the lexer can detect overflows in integer constants.
Instead, right now the constant value gets converted to 'lua_Number' and you silently
overflow by losing precision.
We can see in 'luaO_str2num':
size_t luaO_str2num (const char *s, TValue *o) {
lua_Integer i; lua_Number n;
const char *e;
if ((e = l_str2int(s, &i)) != NULL) { /* try as an integer */
setivalue(o, i);
}
else if ((e = l_str2d(s, &n)) != NULL) { /* else try as a float */
setfltvalue(o, n);
}
else
return 0; /* conversion failed */
return (e - s) + 1; /* success; return string size */
}
If 'l_str2int' would accept additional integer pointer acting as overflow flag we
could easily do something like:
else if (!overflow && (e = l_str2d(s, &n)) != NULL) { /* else try as a float */
setfltvalue(o, n);
}
this would then correctly return '0' and lexer would correctly report all constant
decimal numbers that overflow.
Additionally I see no reason for not checking hexadecimal constant values for overflow
wish any of the devs could address this.
I get it that nobody in their right mind would just write constant number values that
straight up overflow, but this seems like a trivial fix.