> That's because this parses as -(9223372036854775808) so it overflows before the - operator is applied.
you are correct that the parser is tokenizing the - before calling l_str2int, and thus the lua_Integer overflows before negate is applied to it - thus it is handled by the str2d instead
> This is an issue common to many languages.
- this is a lexical parse error, not an arithmetic behavior due to user code
- (my speculation) this is a new issue due to the introduction of ints and floats, and likely an oversight in the dual handling of literals
From: Andrew Gierth <andrew@tao11.riddles.org.uk>
Sent: Thursday, March 26, 2020 8:36 PM
To: Payo Nel <payonel@hotmail.com>
Cc: lua-l@lists.lua.org <lua-l@lists.lua.org>
Subject: Re: lexical parse of hex literal fails to handle overflow: lua 5.3 and 5.4-alpha
>>>>> "Payo" == Payo Nel <payonel@hotmail.com> writes:
Payo> the parser also incorrectly "upgrades" a valid integer to a float
Payo> value with a minimum integer value:
Payo> tonumber is correct here:
Payo> > tonumber('-9223372036854775808',10)
Payo> -9223372036854775808
Payo> lexical parse is not
Payo> > -9223372036854775808
Payo> -9.2233720368548e+18
That's because this parses as -(9223372036854775808) so it overflows
before the - operator is applied. This is an issue common to many
languages.
--
Andrew.