diff options
author | zeertzjq <zeertzjq@outlook.com> | 2022-10-26 20:10:41 +0800 |
---|---|---|
committer | zeertzjq <zeertzjq@outlook.com> | 2022-10-26 20:53:39 +0800 |
commit | 46a54dd6a03f51ba08142abe0aa5710705917987 (patch) | |
tree | 6b88d5ab645201a103cad3a67a98eadb07e6e5b4 | |
parent | ef363ed37cdf5c460cca840aebc825011e0294ee (diff) | |
download | rneovim-46a54dd6a03f51ba08142abe0aa5710705917987.tar.gz rneovim-46a54dd6a03f51ba08142abe0aa5710705917987.tar.bz2 rneovim-46a54dd6a03f51ba08142abe0aa5710705917987.zip |
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)
https://github.com/vim/vim/commit/ffdf8adfa8108d4765fdc68abbd2fe49a4292b25
Co-authored-by: Bram Moolenaar <Bram@vim.org>
-rw-r--r-- | src/nvim/eval.c | 6 | ||||
-rw-r--r-- | src/nvim/testdir/test_blob.vim | 1 | ||||
-rw-r--r-- | src/nvim/testdir/test_filter_map.vim | 6 | ||||
-rw-r--r-- | test/unit/eval/typval_spec.lua | 8 |
4 files changed, 12 insertions, 9 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c index ffbe66aa25..8bd91ec9a2 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -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; diff --git a/src/nvim/testdir/test_blob.vim b/src/nvim/testdir/test_blob.vim index c5a217f36f..770b2d16ef 100644 --- a/src/nvim/testdir/test_blob.vim +++ b/src/nvim/testdir/test_blob.vim @@ -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')) diff --git a/src/nvim/testdir/test_filter_map.vim b/src/nvim/testdir/test_filter_map.vim index ebcb6699c6..c75177ea39 100644 --- a/src/nvim/testdir/test_filter_map.vim +++ b/src/nvim/testdir/test_filter_map.vim @@ -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() diff --git a/test/unit/eval/typval_spec.lua b/test/unit/eval/typval_spec.lua index 6387f89fe4..34dbf592a5 100644 --- a/test/unit/eval/typval_spec.lua +++ b/test/unit/eval/typval_spec.lua @@ -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({}) |