Merge pull request #21054 from max397574/fix/deepcopy_vimNIL

fix(lua): make `vim.deepcopy` work with `vim.NIL`
This commit is contained in:
bfredl
2022-11-14 22:26:22 +01:00
committed by GitHub
2 changed files with 9 additions and 0 deletions

View File

@@ -49,6 +49,9 @@ vim.deepcopy = (function()
if f then
return f(orig, cache or {})
else
if type(orig) == 'userdata' and orig == vim.NIL then
return vim.NIL
end
error('Cannot deepcopy object of type ' .. type(orig))
end
end

View File

@@ -419,6 +419,12 @@ describe('lua stdlib', function()
return getmetatable(t2) == mt
]]))
ok(exec_lua([[
local t1 = {a = vim.NIL}
local t2 = vim.deepcopy(t1)
return t2.a == vim.NIL
]]))
matches('Cannot deepcopy object of type thread',
pcall_err(exec_lua, [[
local thread = coroutine.create(function () return 0 end)