commit 2ad84286375112524e118a4f6ced68782b285a52
parent b0f39f3ef5502c037b5bdb0da3d45d312b7fdc2a
Author: bfredl <bjorn.linse@gmail.com>
Date: Sat, 13 Jul 2024 14:55:35 +0200
Merge pull request #29659 from amitds1997/fix/empty-dict-encoding
fix(lua)!: do not use typed table for empty dict
Diffstat:
4 files changed, 9 insertions(+), 11 deletions(-)
diff --git a/runtime/doc/news.txt b/runtime/doc/news.txt
@@ -69,7 +69,8 @@ LSP
LUA
-• TODO
+• API functions now consistently return an empty dictionary as
+ |vim.empty_dict()|. Earlier, a |lua-special-tbl| was sometimes used.
OPTIONS
diff --git a/src/nvim/lua/converter.c b/src/nvim/lua/converter.c
@@ -703,14 +703,10 @@ void nlua_push_Boolean(lua_State *lstate, const Boolean b, int flags)
void nlua_push_Dictionary(lua_State *lstate, const Dictionary dict, int flags)
FUNC_ATTR_NONNULL_ALL
{
- if (dict.size == 0 && (flags & kNluaPushSpecial)) {
- nlua_create_typed_table(lstate, 0, 0, kObjectTypeDictionary);
- } else {
- lua_createtable(lstate, 0, (int)dict.size);
- if (dict.size == 0 && !(flags & kNluaPushSpecial)) {
- nlua_pushref(lstate, nlua_global_refs->empty_dict_ref);
- lua_setmetatable(lstate, -2);
- }
+ lua_createtable(lstate, 0, (int)dict.size);
+ if (dict.size == 0) {
+ nlua_pushref(lstate, nlua_global_refs->empty_dict_ref);
+ lua_setmetatable(lstate, -2);
}
for (size_t i = 0; i < dict.size; i++) {
nlua_push_String(lstate, dict.items[i].key, flags);
diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua
@@ -1500,6 +1500,8 @@ describe('API', function()
eq('Dictionary is locked', pcall_err(request, 'nvim_set_vvar', 'nosuchvar', 42))
api.nvim_set_vvar('errmsg', 'set by API')
eq('set by API', api.nvim_get_vvar('errmsg'))
+ api.nvim_set_vvar('completed_item', { word = 'a', user_data = vim.empty_dict() })
+ eq({}, api.nvim_get_vvar('completed_item')['user_data'])
api.nvim_set_vvar('errmsg', 42)
eq('42', eval('v:errmsg'))
api.nvim_set_vvar('oldfiles', { 'one', 'two' })
diff --git a/test/functional/lua/vim_spec.lua b/test/functional/lua/vim_spec.lua
@@ -1205,8 +1205,7 @@ describe('lua stdlib', function()
]])
eq(true, exec_lua([[return next(vim.fn.FooFunc(3)) == nil ]]))
eq(3, eval('g:test'))
- -- compat: nvim_call_function uses "special" value for empty dict
- eq(true, exec_lua([[return next(vim.api.nvim_call_function("FooFunc", {5})) == true ]]))
+ eq(true, exec_lua([[return vim.tbl_isempty(vim.api.nvim_call_function("FooFunc", {5}))]]))
eq(5, eval('g:test'))
eq({ 2, 'foo', true }, exec_lua([[return vim.fn.VarArg(2, "foo", true)]]))