aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/shared.lua
diff options
context:
space:
mode:
authorBjörn Linse <bjorn.linse@gmail.com>2020-02-15 18:10:48 +0100
committerGitHub <noreply@github.com>2020-02-15 18:10:48 +0100
commitdc0e534a9168452b4fd78a1cca02214d6d9c73d0 (patch)
tree9e3e0aa237f3f965d940c41ac1df2fc25036d57f /runtime/lua/vim/shared.lua
parentbb331a9b31c441d47fc2cb3dcb87e0573f519dd9 (diff)
parentcdb729b7462cfef28a0264cb75bffe69182c5275 (diff)
downloadrneovim-dc0e534a9168452b4fd78a1cca02214d6d9c73d0.tar.gz
rneovim-dc0e534a9168452b4fd78a1cca02214d6d9c73d0.tar.bz2
rneovim-dc0e534a9168452b4fd78a1cca02214d6d9c73d0.zip
Merge pull request #11864 from h-michael/deepcopy
lua: vim.deepcopy() and vim.tbl_extend() should preserve vim.empty_dict()
Diffstat (limited to 'runtime/lua/vim/shared.lua')
-rw-r--r--runtime/lua/vim/shared.lua15
1 files changed, 15 insertions, 0 deletions
diff --git a/runtime/lua/vim/shared.lua b/runtime/lua/vim/shared.lua
index ea1117a906..6eb7a970e4 100644
--- a/runtime/lua/vim/shared.lua
+++ b/runtime/lua/vim/shared.lua
@@ -20,6 +20,11 @@ vim.deepcopy = (function()
local deepcopy_funcs = {
table = function(orig)
local copy = {}
+
+ if vim._empty_dict_mt ~= nil and getmetatable(orig) == vim._empty_dict_mt then
+ copy = vim.empty_dict()
+ end
+
for k, v in pairs(orig) do
copy[vim.deepcopy(k)] = vim.deepcopy(v)
end
@@ -169,9 +174,19 @@ function vim.tbl_extend(behavior, ...)
if (behavior ~= 'error' and behavior ~= 'keep' and behavior ~= 'force') then
error('invalid "behavior": '..tostring(behavior))
end
+
+ if select('#', ...) < 2 then
+ error('wrong number of arguments (given '..tostring(1 + select('#', ...))..', expected at least 3)')
+ end
+
local ret = {}
+ if vim._empty_dict_mt ~= nil and getmetatable(select(1, ...)) == vim._empty_dict_mt then
+ ret = vim.empty_dict()
+ end
+
for i = 1, select('#', ...) do
local tbl = select(i, ...)
+ vim.validate{["after the second argument"] = {tbl,'t'}}
if tbl then
for k, v in pairs(tbl) do
if behavior ~= 'force' and ret[k] ~= nil then