From 042e118eef1daad967f3d0f4fc400242523d5725 Mon Sep 17 00:00:00 2001 From: mpeterv Date: Mon, 18 Apr 2016 00:17:42 +0300 Subject: [PATCH] Convert numbers to float only on Lua 5.3 Also don't crash if somehow tonumber returned nil. --- src/luacheck/linearize.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/luacheck/linearize.lua b/src/luacheck/linearize.lua index b8ed7485..63591094 100644 --- a/src/luacheck/linearize.lua +++ b/src/luacheck/linearize.lua @@ -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