mirror of
https://github.com/neovim/neovim.git
synced 2025-09-05 19:08:15 +00:00
vim-patch:8.2.1852: map() returing zero for NULL list is unexpected
Problem: map() returing zero for NULL list is unexpected.
Solution: Return the empty list. (closes vim/vim#7133)
ffdf8adfa8
Co-authored-by: Bram Moolenaar <Bram@vim.org>
This commit is contained in:
@@ -4786,20 +4786,20 @@ void filter_map(typval_T *argvars, typval_T *rettv, int map)
|
||||
int save_did_emsg;
|
||||
int idx = 0;
|
||||
|
||||
// Always return the first argument, also on failure.
|
||||
tv_copy(&argvars[0], rettv);
|
||||
|
||||
if (argvars[0].v_type == VAR_BLOB) {
|
||||
tv_copy(&argvars[0], rettv);
|
||||
if ((b = argvars[0].vval.v_blob) == NULL) {
|
||||
return;
|
||||
}
|
||||
} else if (argvars[0].v_type == VAR_LIST) {
|
||||
tv_copy(&argvars[0], rettv);
|
||||
if ((l = argvars[0].vval.v_list) == NULL
|
||||
|| (!map
|
||||
&& var_check_lock(tv_list_locked(l), arg_errmsg, TV_TRANSLATE))) {
|
||||
return;
|
||||
}
|
||||
} else if (argvars[0].v_type == VAR_DICT) {
|
||||
tv_copy(&argvars[0], rettv);
|
||||
if ((d = argvars[0].vval.v_dict) == NULL
|
||||
|| (!map && var_check_lock(d->dv_lock, arg_errmsg, TV_TRANSLATE))) {
|
||||
return;
|
||||
|
@@ -274,6 +274,7 @@ endfunc
|
||||
|
||||
" filter() item in blob
|
||||
func Test_blob_filter()
|
||||
call assert_equal(v:_null_blob, filter(v:_null_blob, '0'))
|
||||
call assert_equal(0z, filter(0zDEADBEEF, '0'))
|
||||
call assert_equal(0zADBEEF, filter(0zDEADBEEF, 'v:val != 0xDE'))
|
||||
call assert_equal(0zDEADEF, filter(0zDEADBEEF, 'v:val != 0xBE'))
|
||||
|
@@ -89,8 +89,10 @@ func Test_map_filter_fails()
|
||||
call assert_fails("let l = filter([1, 2, 3], '{}')", 'E728:')
|
||||
call assert_fails("let l = filter({'k' : 10}, '{}')", 'E728:')
|
||||
call assert_fails("let l = filter([1, 2], {})", 'E731:')
|
||||
call assert_equal(0, map(v:_null_list, '"> " .. v:val'))
|
||||
call assert_equal(0, map(v:_null_dict, '"> " .. v:val'))
|
||||
call assert_equal(v:_null_list, filter(v:_null_list, 0))
|
||||
call assert_equal(v:_null_dict, filter(v:_null_dict, 0))
|
||||
call assert_equal(v:_null_list, map(v:_null_list, '"> " .. v:val'))
|
||||
call assert_equal(v:_null_dict, map(v:_null_dict, '"> " .. v:val'))
|
||||
endfunc
|
||||
|
||||
func Test_map_and_modify()
|
||||
|
@@ -2253,8 +2253,8 @@ describe('typval.c', function()
|
||||
local d1 = dict()
|
||||
alloc_log:check({a.dict(d1)})
|
||||
eq(1, d1.dv_refcount)
|
||||
eq(false, tv_dict_equal(nil, d1))
|
||||
eq(false, tv_dict_equal(d1, nil))
|
||||
eq(true, tv_dict_equal(nil, d1))
|
||||
eq(true, tv_dict_equal(d1, nil))
|
||||
eq(true, tv_dict_equal(d1, d1))
|
||||
eq(1, d1.dv_refcount)
|
||||
alloc_log:check({})
|
||||
@@ -2721,8 +2721,8 @@ describe('typval.c', function()
|
||||
local d1 = lua2typvalt({})
|
||||
alloc_log:check({a.dict(d1.vval.v_dict)})
|
||||
eq(1, d1.vval.v_dict.dv_refcount)
|
||||
eq(false, tv_equal(nd, d1))
|
||||
eq(false, tv_equal(d1, nd))
|
||||
eq(true, tv_equal(nd, d1))
|
||||
eq(true, tv_equal(d1, nd))
|
||||
eq(true, tv_equal(d1, d1))
|
||||
eq(1, d1.vval.v_dict.dv_refcount)
|
||||
alloc_log:check({})
|
||||
|
Reference in New Issue
Block a user