diff --git a/errors.lua b/errors.lua index c2b8ae2..84a9798 100644 --- a/errors.lua +++ b/errors.lua @@ -146,6 +146,7 @@ return function (module_name) __index = function (t, k) local keys = {} 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) end }) diff --git a/test/test_errors.lua b/test/test_errors.lua index 41757a9..69a508a 100644 --- a/test/test_errors.lua +++ b/test/test_errors.lua @@ -107,6 +107,11 @@ SUITE:addTest('Strict tables throw errors on unknown indices', function() bad_call(function() return t.hello 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) + --------------------------------------------------------------------------------