diff options
author | Lewis Russell <lewis6991@gmail.com> | 2022-12-15 08:03:31 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-15 08:03:31 +0000 |
commit | 3091fa778a4f4fe6ff48527c6a29e3be874f46c7 (patch) | |
tree | 0464a2b496b72523b2f6487374ef0d09b57a8fd9 | |
parent | 0887ad1cbb050d2bc6169ad46aa07cf42c90493f (diff) | |
parent | 26c918d03f5b38df900316c0601065ec1ea96264 (diff) | |
download | rneovim-3091fa778a4f4fe6ff48527c6a29e3be874f46c7.tar.gz rneovim-3091fa778a4f4fe6ff48527c6a29e3be874f46c7.tar.bz2 rneovim-3091fa778a4f4fe6ff48527c6a29e3be874f46c7.zip |
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
-rw-r--r-- | runtime/lua/vim/shared.lua | 9 | ||||
-rw-r--r-- | test/functional/lua/vim_spec.lua | 2 |
2 files changed, 6 insertions, 5 deletions
diff --git a/runtime/lua/vim/shared.lua b/runtime/lua/vim/shared.lua index 9129500866..5ffd11682c 100644 --- a/runtime/lua/vim/shared.lua +++ b/runtime/lua/vim/shared.lua @@ -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 diff --git a/test/functional/lua/vim_spec.lua b/test/functional/lua/vim_spec.lua index e390619a5a..90eccc49c8 100644 --- a/test/functional/lua/vim_spec.lua +++ b/test/functional/lua/vim_spec.lua @@ -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() |