fix(lua): fix vim.deepcopy for metatables & cycled tables (#16435)

vim.deepcopy previously didn't retain metatables in copies
and caused stackoverflow on recursive tables/cycled tables this
fixes these issues
This commit is contained in:
Shadman
2021-11-26 16:06:43 +06:00
committed by GitHub
parent 3451121a4e
commit eb876a0a6f
2 changed files with 23 additions and 10 deletions

View File

@@ -396,6 +396,20 @@ describe('lua stdlib', function()
return t1.f() ~= t2.f()
]]))
ok(exec_lua([[
local t1 = {a = 5}
t1.self = t1
local t2 = vim.deepcopy(t1)
return t2.self == t2 and t2.self ~= t1
]]))
ok(exec_lua([[
local mt = {mt=true}
local t1 = setmetatable({a = 5}, mt)
local t2 = vim.deepcopy(t1)
return getmetatable(t2) == mt
]]))
eq('Error executing lua: vim/shared.lua:0: Cannot deepcopy object of type thread',
pcall_err(exec_lua, [[
local thread = coroutine.create(function () return 0 end)