summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2020-08-19 16:00:06 +0200
committerBram Moolenaar <Bram@vim.org>2020-08-19 16:00:06 +0200
commitf8abbf37d66c41d980284e28e0e38a399890e918 (patch)
tree8226b8ed4e6ac5969ed05bf20b2bcc44794ce442
parentaf8822ce085e3bd8edeb52cbb7306ddd42427d39 (diff)
downloadvim-git-f8abbf37d66c41d980284e28e0e38a399890e918.tar.gz
patch 8.2.1486: Vim9: readdir() expression doesn't accept boolv8.2.1486
Problem: Vim9: readdir() expression doesn't accept bool. Solution: Merge with code for readdirex(). (closes #6737)
-rw-r--r--src/filepath.c73
-rw-r--r--src/testdir/test_vim9_func.vim3
-rw-r--r--src/version.c2
3 files changed, 41 insertions, 37 deletions
diff --git a/src/filepath.c b/src/filepath.c
index d4592eba3..e4798d2a0 100644
--- a/src/filepath.c
+++ b/src/filepath.c
@@ -1373,10 +1373,11 @@ f_pathshorten(typval_T *argvars, typval_T *rettv)
}
/*
- * Evaluate "expr" (= "context") for readdir().
+ * Common code for readdir_checkitem() and readdirex_checkitem().
+ * Either "name" or "dict" is NULL.
*/
static int
-readdir_checkitem(void *context, void *item)
+checkitem_common(void *context, char_u *name, dict_T *dict)
{
typval_T *expr = (typval_T *)context;
typval_T save_val;
@@ -1384,27 +1385,55 @@ readdir_checkitem(void *context, void *item)
typval_T argv[2];
int retval = 0;
int error = FALSE;
- char_u *name = (char_u*)item;
prepare_vimvar(VV_VAL, &save_val);
- set_vim_var_string(VV_VAL, name, -1);
- argv[0].v_type = VAR_STRING;
- argv[0].vval.v_string = name;
+ if (name != NULL)
+ {
+ set_vim_var_string(VV_VAL, name, -1);
+ argv[0].v_type = VAR_STRING;
+ argv[0].vval.v_string = name;
+ }
+ else
+ {
+ set_vim_var_dict(VV_VAL, dict);
+ argv[0].v_type = VAR_DICT;
+ argv[0].vval.v_dict = dict;
+ }
if (eval_expr_typval(expr, argv, 1, &rettv) == FAIL)
goto theend;
+ // We want to use -1, but also true/false should be allowed.
+ if (rettv.v_type == VAR_SPECIAL || rettv.v_type == VAR_BOOL)
+ {
+ rettv.v_type = VAR_NUMBER;
+ rettv.vval.v_number = rettv.vval.v_number == VVAL_TRUE;
+ }
retval = tv_get_number_chk(&rettv, &error);
if (error)
retval = -1;
clear_tv(&rettv);
theend:
- set_vim_var_string(VV_VAL, NULL, 0);
+ if (name != NULL)
+ set_vim_var_string(VV_VAL, NULL, 0);
+ else
+ set_vim_var_dict(VV_VAL, NULL);
restore_vimvar(VV_VAL, &save_val);
return retval;
}
+/*
+ * Evaluate "expr" (= "context") for readdir().
+ */
+ static int
+readdir_checkitem(void *context, void *item)
+{
+ char_u *name = (char_u *)item;
+
+ return checkitem_common(context, name, NULL);
+}
+
static int
readdirex_dict_arg(typval_T *tv, int *cmp)
{
@@ -1477,37 +1506,9 @@ f_readdir(typval_T *argvars, typval_T *rettv)
static int
readdirex_checkitem(void *context, void *item)
{
- typval_T *expr = (typval_T *)context;
- typval_T save_val;
- typval_T rettv;
- typval_T argv[2];
- int retval = 0;
- int error = FALSE;
dict_T *dict = (dict_T*)item;
- prepare_vimvar(VV_VAL, &save_val);
- set_vim_var_dict(VV_VAL, dict);
- argv[0].v_type = VAR_DICT;
- argv[0].vval.v_dict = dict;
-
- if (eval_expr_typval(expr, argv, 1, &rettv) == FAIL)
- goto theend;
-
- // We want to use -1, but also true/false should be allowed.
- if (rettv.v_type == VAR_SPECIAL || rettv.v_type == VAR_BOOL)
- {
- rettv.v_type = VAR_NUMBER;
- rettv.vval.v_number = rettv.vval.v_number == VVAL_TRUE;
- }
- retval = tv_get_number_chk(&rettv, &error);
- if (error)
- retval = -1;
- clear_tv(&rettv);
-
-theend:
- set_vim_var_dict(VV_VAL, NULL);
- restore_vimvar(VV_VAL, &save_val);
- return retval;
+ return checkitem_common(context, NULL, dict);
}
/*
diff --git a/src/testdir/test_vim9_func.vim b/src/testdir/test_vim9_func.vim
index 751cd6d60..ad59844d5 100644
--- a/src/testdir/test_vim9_func.vim
+++ b/src/testdir/test_vim9_func.vim
@@ -1386,7 +1386,8 @@ def Test_search()
assert_equal(2, search('bar', 'W', 0, 0, {-> val == 1}))
enddef
-def Test_readdirex()
+def Test_readdir()
+ eval expand('.')->readdir({e -> e[0] !=# '.'})
eval expand('.')->readdirex({e -> e.name[0] !=# '.'})
enddef
diff --git a/src/version.c b/src/version.c
index 3c1eb1cf5..8c98eb413 100644
--- a/src/version.c
+++ b/src/version.c
@@ -755,6 +755,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 1486,
+/**/
1485,
/**/
1484,