Mercurial > vim
diff src/list.c @ 25597:0fdacd8f0cf3 v8.2.3335
patch 8.2.3335: Vim9: not enough tests run with Vim9
Commit: https://github.com/vim/vim/commit/ef98257593a0abf1300d0f70358dc45a70a62580
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Aug 12 19:27:57 2021 +0200
patch 8.2.3335: Vim9: not enough tests run with Vim9
Problem: Vim9: not enough tests run with Vim9.
Solution: Run a few more tests in Vim9 script and :def function. Fix that
items(), keys() and values9) return zero for a NULL dict.
Make join() return an empty string for a NULL list. Make sort()
return an empty list for a NULL list.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 12 Aug 2021 19:30:03 +0200 |
parents | ea69398b40d1 |
children | b85e44974a08 |
line wrap: on
line diff
--- a/src/list.c +++ b/src/list.c @@ -1436,15 +1436,15 @@ f_join(typval_T *argvars, typval_T *rett emsg(_(e_listreq)); return; } + rettv->v_type = VAR_STRING; if (argvars[0].vval.v_list == NULL) return; + if (argvars[1].v_type == VAR_UNKNOWN) sep = (char_u *)" "; else sep = tv_get_string_chk(&argvars[1]); - rettv->v_type = VAR_STRING; - if (sep != NULL) { ga_init2(&ga, (int)sizeof(char), 80); @@ -1968,11 +1968,13 @@ do_sort_uniq(typval_T *argvars, typval_T else { l = argvars[0].vval.v_list; - if (l == NULL || value_check_lock(l->lv_lock, + if (l != NULL && value_check_lock(l->lv_lock, (char_u *)(sort ? N_("sort() argument") : N_("uniq() argument")), TRUE)) goto theend; rettv_list_set(rettv, l); + if (l == NULL) + goto theend; CHECK_LIST_MATERIALIZE(l); len = list_len(l); @@ -3110,32 +3112,35 @@ f_reverse(typval_T *argvars, typval_T *r if (argvars[0].v_type != VAR_LIST) semsg(_(e_listblobarg), "reverse()"); - else if ((l = argvars[0].vval.v_list) != NULL + else + { + l = argvars[0].vval.v_list; + rettv_list_set(rettv, l); + if (l != NULL && !value_check_lock(l->lv_lock, (char_u *)N_("reverse() argument"), TRUE)) - { - if (l->lv_first == &range_list_item) { - varnumber_T new_start = l->lv_u.nonmat.lv_start + if (l->lv_first == &range_list_item) + { + varnumber_T new_start = l->lv_u.nonmat.lv_start + (l->lv_len - 1) * l->lv_u.nonmat.lv_stride; - l->lv_u.nonmat.lv_end = new_start + l->lv_u.nonmat.lv_end = new_start - (l->lv_u.nonmat.lv_end - l->lv_u.nonmat.lv_start); - l->lv_u.nonmat.lv_start = new_start; - l->lv_u.nonmat.lv_stride = -l->lv_u.nonmat.lv_stride; - rettv_list_set(rettv, l); - return; + l->lv_u.nonmat.lv_start = new_start; + l->lv_u.nonmat.lv_stride = -l->lv_u.nonmat.lv_stride; + return; + } + li = l->lv_u.mat.lv_last; + l->lv_first = l->lv_u.mat.lv_last = NULL; + l->lv_len = 0; + while (li != NULL) + { + ni = li->li_prev; + list_append(l, li); + li = ni; + } + l->lv_u.mat.lv_idx = l->lv_len - l->lv_u.mat.lv_idx - 1; } - li = l->lv_u.mat.lv_last; - l->lv_first = l->lv_u.mat.lv_last = NULL; - l->lv_len = 0; - while (li != NULL) - { - ni = li->li_prev; - list_append(l, li); - li = ni; - } - rettv_list_set(rettv, l); - l->lv_u.mat.lv_idx = l->lv_len - l->lv_u.mat.lv_idx - 1; } }