aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax <max.heinzer397@gmx.ch>2022-11-14 20:26:27 +0100
committerMax <max.heinzer397@gmx.ch>2022-11-14 21:14:27 +0100
commite15f61b1bd60f6a198a0d9969cea407784ff71d0 (patch)
tree15b8c595ede5b3504948f1eaf3e487a9d050684d
parentf8c671827710c6e9cca3bfd60c32098b2be8239a (diff)
downloadrneovim-e15f61b1bd60f6a198a0d9969cea407784ff71d0.tar.gz
rneovim-e15f61b1bd60f6a198a0d9969cea407784ff71d0.tar.bz2
rneovim-e15f61b1bd60f6a198a0d9969cea407784ff71d0.zip
fix(lua): make `vim.deepcopy` work with `vim.NIL`
style: changed double quotes to single quotes feat: add tests fix tests
-rw-r--r--runtime/lua/vim/shared.lua3
-rw-r--r--test/functional/lua/vim_spec.lua6
2 files changed, 9 insertions, 0 deletions
diff --git a/runtime/lua/vim/shared.lua b/runtime/lua/vim/shared.lua
index f980547ae4..f4a57c13c8 100644
--- 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
index 6d0d87746c..21f2c19fbb 100644
--- 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)