Skip to content

Commit

Permalink
patch 8.2.2075: error for const argument to mapnew()
Browse files Browse the repository at this point in the history
Problem:    Error for const argument to mapnew().
Solution:   Don't give an error. (closes #7400)
  • Loading branch information
brammool committed Dec 1, 2020
1 parent 4324d87 commit 57cf497
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/list.c
Original file line number Diff line number Diff line change
Expand Up @@ -2065,7 +2065,7 @@ filter_map(typval_T *argvars, typval_T *rettv, filtermap_T filtermap)

--todo;
di = HI2DI(hi);
if (filtermap != FILTERMAP_FILTER
if (filtermap == FILTERMAP_MAP
&& (value_check_lock(di->di_tv.v_lock,
arg_errmsg, TRUE)
|| var_check_ro(di->di_flags,
Expand Down Expand Up @@ -2225,12 +2225,12 @@ filter_map(typval_T *argvars, typval_T *rettv, filtermap_T filtermap)
}
else
{
// Materialized list from range(): loop over the items
// Materialized list: loop over the items
for (li = l->lv_first; li != NULL; li = nli)
{
typval_T newtv;

if (filtermap != FILTERMAP_FILTER && value_check_lock(
if (filtermap == FILTERMAP_MAP && value_check_lock(
li->li_tv.v_lock, arg_errmsg, TRUE))
break;
nli = li->li_next;
Expand Down
6 changes: 6 additions & 0 deletions src/testdir/test_filter_map.vim
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,19 @@ func Test_mapnew_dict()
let dout = mapnew(din, {k, v -> string(v)})
call assert_equal(#{one: 1, two: 2}, din)
call assert_equal(#{one: '1', two: '2'}, dout)

const dconst = #{one: 1, two: 2, three: 3}
call assert_equal(#{one: 2, two: 3, three: 4}, mapnew(dconst, {_, v -> v + 1}))
endfunc

func Test_mapnew_list()
let lin = [1, 2, 3]
let lout = mapnew(lin, {k, v -> string(v)})
call assert_equal([1, 2, 3], lin)
call assert_equal(['1', '2', '3'], lout)

const lconst = [1, 2, 3]
call assert_equal([2, 3, 4], mapnew(lconst, {_, v -> v + 1}))
endfunc

func Test_mapnew_blob()
Expand Down
2 changes: 2 additions & 0 deletions src/version.c
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,8 @@ static char *(features[]) =

static int included_patches[] =
{ /* Add new patch number below this line */
/**/
2075,
/**/
2074,
/**/
Expand Down

0 comments on commit 57cf497

Please sign in to comment.