From d4fa8bac0ab2e98168350c00a3053612d736d40d Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Fri, 13 Nov 2020 11:29:41 +0000 Subject: [PATCH] [Fix] Deduct type of a table methods --- lualib/lua_selectors/init.lua | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/lualib/lua_selectors/init.lua b/lualib/lua_selectors/init.lua index 8de79f767..54d42f242 100644 --- a/lualib/lua_selectors/init.lua +++ b/lualib/lua_selectors/init.lua @@ -338,20 +338,24 @@ exports.parse_selector = function(cfg, str) }, map_type = 'string', process = function(inp, t, args) + local ret if t == 'table' then - return inp[method_name],'string' + -- Plain table field + ret = inp[method_name] else -- We call method unpacking arguments and dropping all but the first result returned - local ret = (inp[method_name](inp, unpack_function(args or E))) - local ret_type = type(ret) - -- Now apply types heuristic - if ret_type == 'string' then - return ret,'string' - elseif ret_type == 'table' then - return ret,'string_list' - else - return implicit_tostring(ret_type, ret) - end + ret = (inp[method_name](inp, unpack_function(args or E))) + end + + local ret_type = type(ret) + -- Now apply types heuristic + if ret_type == 'string' then + return ret,'string' + elseif ret_type == 'table' then + -- TODO: we need to ensure that 1) table is numeric 2) table has merely strings + return ret,'string_list' + else + return implicit_tostring(ret_type, ret) end end, } -- 2.39.5