mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
Merge pull request #21426 from williamboman/fix/tbl_get-nil-return-val
fix(lua): always return nil values in vim.tbl_get when no results
This commit is contained in:
commit
3091fa778a
@ -395,15 +395,14 @@ end
|
||||
function vim.tbl_get(o, ...)
|
||||
local keys = { ... }
|
||||
if #keys == 0 then
|
||||
return
|
||||
return nil
|
||||
end
|
||||
for i, k in ipairs(keys) do
|
||||
if type(o[k]) ~= 'table' and next(keys, i) then
|
||||
return nil
|
||||
end
|
||||
o = o[k]
|
||||
if o == nil then
|
||||
return
|
||||
return nil
|
||||
elseif type(o) ~= 'table' and next(keys, i) then
|
||||
return nil
|
||||
end
|
||||
end
|
||||
return o
|
||||
|
@ -512,6 +512,8 @@ describe('lua stdlib', function()
|
||||
eq(NIL, exec_lua("return vim.tbl_get({ unindexable = function () end }, 'unindexable', 'missing_key')"))
|
||||
eq(NIL, exec_lua("return vim.tbl_get({}, 'missing_key')"))
|
||||
eq(NIL, exec_lua("return vim.tbl_get({})"))
|
||||
eq(1, exec_lua("return select('#', vim.tbl_get({}))"))
|
||||
eq(1, exec_lua("return select('#', vim.tbl_get({ nested = {} }, 'nested', 'missing_key'))"))
|
||||
end)
|
||||
|
||||
it('vim.tbl_extend', function()
|
||||
|
Loading…
Reference in New Issue
Block a user