commit 4541c450812bb5252a63307772add143be1ee9c7
parent f8c671827710c6e9cca3bfd60c32098b2be8239a
Author: bfredl <bjorn.linse@gmail.com>
Date: Mon, 14 Nov 2022 22:26:22 +0100
Merge pull request #21054 from max397574/fix/deepcopy_vimNIL
fix(lua): make `vim.deepcopy` work with `vim.NIL`
Diffstat:
2 files changed, 9 insertions(+), 0 deletions(-)
diff --git a/runtime/lua/vim/shared.lua b/runtime/lua/vim/shared.lua
@@ -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
diff --git a/test/functional/lua/vim_spec.lua b/test/functional/lua/vim_spec.lua
@@ -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)