To: vim_dev@googlegroups.com Subject: Patch 8.2.1486 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.1486 Problem: Vim9: readdir() expression doesn't accept bool. Solution: Merge with code for readdirex(). (closes #6737) Files: src/filepath.c, src/testdir/test_vim9_func.vim *** ../vim-8.2.1485/src/filepath.c 2020-08-19 13:54:56.480510305 +0200 --- src/filepath.c 2020-08-19 15:53:21.480966340 +0200 *************** *** 1373,1382 **** } /* ! * Evaluate "expr" (= "context") for readdir(). */ static int ! readdir_checkitem(void *context, void *item) { typval_T *expr = (typval_T *)context; typval_T save_val; --- 1373,1383 ---- } /* ! * Common code for readdir_checkitem() and readdirex_checkitem(). ! * Either "name" or "dict" is NULL. */ static int ! checkitem_common(void *context, char_u *name, dict_T *dict) { typval_T *expr = (typval_T *)context; typval_T save_val; *************** *** 1384,1410 **** 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 (eval_expr_typval(expr, argv, 1, &rettv) == FAIL) goto theend; retval = tv_get_number_chk(&rettv, &error); if (error) retval = -1; clear_tv(&rettv); theend: ! set_vim_var_string(VV_VAL, NULL, 0); restore_vimvar(VV_VAL, &save_val); return retval; } static int readdirex_dict_arg(typval_T *tv, int *cmp) { --- 1385,1439 ---- typval_T argv[2]; int retval = 0; int error = FALSE; prepare_vimvar(VV_VAL, &save_val); ! 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: ! 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,1513 **** 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; } /* --- 1506,1514 ---- static int readdirex_checkitem(void *context, void *item) { dict_T *dict = (dict_T*)item; ! return checkitem_common(context, NULL, dict); } /* *** ../vim-8.2.1485/src/testdir/test_vim9_func.vim 2020-08-19 13:54:56.480510305 +0200 --- src/testdir/test_vim9_func.vim 2020-08-19 15:58:23.871003143 +0200 *************** *** 1386,1392 **** assert_equal(2, search('bar', 'W', 0, 0, {-> val == 1})) enddef ! def Test_readdirex() eval expand('.')->readdirex({e -> e.name[0] !=# '.'}) enddef --- 1386,1393 ---- assert_equal(2, search('bar', 'W', 0, 0, {-> val == 1})) enddef ! def Test_readdir() ! eval expand('.')->readdir({e -> e[0] !=# '.'}) eval expand('.')->readdirex({e -> e.name[0] !=# '.'}) enddef *** ../vim-8.2.1485/src/version.c 2020-08-19 13:54:56.480510305 +0200 --- src/version.c 2020-08-19 15:59:15.830669242 +0200 *************** *** 756,757 **** --- 756,759 ---- { /* Add new patch number below this line */ + /**/ + 1486, /**/ -- Married is a three ring circus: First comes the engagement ring. Then comes the wedding ring. Then comes the suffering. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///