Skip to content

Commit 45086b3

Browse files
committed
fix(util.flatten): iterator table in order
1 parent 0d46562 commit 45086b3

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

lua/gitsigns/util.lua

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -446,17 +446,20 @@ end
446446
--- Flattens a nested table structure into a flat array of strings. Only
447447
--- traverses numeric keys, recursively flattening tables and collecting
448448
--- strings.
449-
--- @param x table<any,any> The input table to flatten.
450-
--- @return string[] A flat array of strings extracted from the nested table.
449+
--- @param x table<integer,string|string[]?> The input table to flatten.
450+
--- @return string[] # A flat array of strings extracted from the nested table.
451451
function M.flatten(x)
452452
local ret = {} --- @type string[]
453-
for k, v in pairs(x) do
454-
if type(k) == 'number' then
455-
if type(v) == 'table' then
456-
vim.list_extend(ret, M.flatten(v))
457-
elseif type(v) == 'string' then
458-
ret[#ret + 1] = v
459-
end
453+
for i = 1, table.maxn(x) do
454+
local v = x[i]
455+
if type(v) == 'table' then
456+
vim.list_extend(ret, M.flatten(v))
457+
elseif type(v) == 'string' then
458+
ret[#ret + 1] = v
459+
elseif v == nil then
460+
-- skip
461+
else
462+
error('Expected string or table, got ' .. type(v))
460463
end
461464
end
462465
return ret

0 commit comments

Comments
 (0)