neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

commit 3091fa778a4f4fe6ff48527c6a29e3be874f46c7
parent 0887ad1cbb050d2bc6169ad46aa07cf42c90493f
Author: Lewis Russell <lewis6991@gmail.com>
Date:   Thu, 15 Dec 2022 08:03:31 +0000

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
Diffstat:
Mruntime/lua/vim/shared.lua | 9++++-----
Mtest/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 @@ -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 @@ -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()