fix(lua): avoid __index when deciding if a table is a list #39556

Problem:
When a table has `__index`, `vim.islist` is unreliable.

Solution:
Index using `rawget`.

(cherry picked from commit 264fbc0ace)
This commit is contained in:
Yi Ming authored and github-actions[bot] committed 2026-05-05 20:54:41 +00:00
1 parent c9cb49358b
commit e67f9c5853
2 files changed
+12 -1

No files matched your search

+1 -1
View File
@@ -960,7 +960,7 @@ function vim.islist(t)
for _ in
pairs(t--[[@as table<any,any>]])
do
if t[j] == nil then
if rawget(t, j) == nil then
return false
end
j = j + 1
+11
View File
@@ -969,6 +969,17 @@ describe('lua stdlib', function()
eq(false, exec_lua('return vim.islist({1, 2, nil, 4})'))
eq(false, exec_lua('return vim.islist({nil, 2, 3, 4})'))
eq(false, exec_lua('return vim.islist({1, [1.5]=2, [3]=3})'))
eq(
false,
exec_lua([[
local t = setmetatable({ 1, [3] = 3 }, {
__index = function()
return 2
end,
})
return vim.islist(t)
]])
)
end)
it('vim.tbl_isempty', function()