Skip to content

Commit

Permalink
Convert numbers to float only on Lua 5.3
Browse files Browse the repository at this point in the history
Also don't crash if somehow tonumber returned nil.
  • Loading branch information
mpeterv committed Apr 17, 2016
1 parent a7e5136 commit 042e118
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/luacheck/linearize.lua
Original file line number Diff line number Diff line change
Expand Up @@ -549,14 +549,14 @@ local function node_to_lua_value(node)
return
end

-- Always convert to float to get consistent results on Lua 5.2/5.3.
if _VERSION ~= "Lua 5.1" and not str:find("[%.eEpP]") then
-- On Lua 5.3 convert to float to get same results as on Lua 5.1 and 5.2.
if _VERSION == "Lua 5.3" and not str:find("[%.eEpP]") then
str = str .. ".0"
end

local number = tonumber(str)

if number == number and number < 1/0 and number > -1/0 then
if number and number == number and number < 1/0 and number > -1/0 then
return number, node[1]
end
end
Expand Down

0 comments on commit 042e118

Please sign in to comment.