1
0

Added specific error message on 'strict table' when table is empty

This commit is contained in:
Jon Michael Aanes 2017-07-10 10:51:07 +02:00
parent 57ddbbf62f
commit b85dc4694a
2 changed files with 6 additions and 0 deletions

View File

@ -146,6 +146,7 @@ return function (module_name)
__index = function (t, k) __index = function (t, k)
local keys = {} local keys = {}
for k in pairs(t) do keys[#keys+1] = k end for k in pairs(t) do keys[#keys+1] = k end
if #keys then external_error(err_hdl, '', 'Attempting to index unknown key %s in an empty table.', k) end
correct_error(err_hdl, '', 'Attempting to index unknown key %s, maybe you meant %s?', k, keys) correct_error(err_hdl, '', 'Attempting to index unknown key %s, maybe you meant %s?', k, keys)
end end
}) })

View File

@ -107,6 +107,11 @@ SUITE:addTest('Strict tables throw errors on unknown indices', function()
bad_call(function() return t.hello end) bad_call(function() return t.hello end)
end) end)
SUITE:addTest('Strict tables throw specific error on empty table', function()
local t = error.strict_table {}
bad_call(function() return t.hello end)
end)
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------