aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAmit Singh <amitds1997@gmail.com>2024-07-11 15:56:52 +0530
committerAmit Singh <amitds1997@gmail.com>2024-07-13 16:42:28 +0530
commit970a27927eb31bdc735f0d7d5e3d07784486c6de (patch)
tree6a106fbbaef11a504ca60dfaea663b7e3bd5e11f /src
parentb1aa8f5eb8a5407e869335e9987b73f8515c37e5 (diff)
downloadrneovim-970a27927eb31bdc735f0d7d5e3d07784486c6de.tar.gz
rneovim-970a27927eb31bdc735f0d7d5e3d07784486c6de.tar.bz2
rneovim-970a27927eb31bdc735f0d7d5e3d07784486c6de.zip
fix(lua)!: do not use typed table for empty dict
Problem: Empty dictionaries are converted into typed tables of the form `{ [true] = 6}` instead of an empty dictionary representation `{}`. This leads to incorrect table representation, along with failure in JSON encoding of such tables as currently tables with only string and number type keys can be encoded. Solution: The typed table logic has been removed from `nlua_push_Dictionary`. The typed table logic is required only for float value conversions which is already handled in `nlua_push_Float`. So, it is(was) no longer required here. Fixes neovim/neovim#29218
Diffstat (limited to 'src')
-rw-r--r--src/nvim/lua/converter.c12
1 files changed, 4 insertions, 8 deletions
diff --git a/src/nvim/lua/converter.c b/src/nvim/lua/converter.c
index c8ad6606bf..c879d731bc 100644
--- 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);