To: vim_dev@googlegroups.com Subject: Patch 9.0.0345 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 9.0.0345 Problem: Error message for list argument could be clearer. Solution: Include the argument number. (Yegappan Lakshmanan, closes #11027) Files: runtime/doc/vim9.txt, src/errors.h, src/evalfunc.c, src/filepath.c, src/insexpand.c, src/list.c, src/match.c, src/mbyte.c, src/proto/typval.pro, src/sign.c, src/terminal.c, src/textprop.c, src/typval.c, src/testdir/test_functions.vim, src/testdir/test_ins_complete.vim, src/testdir/test_match.vim, src/testdir/test_method.vim, src/testdir/test_signs.vim, src/testdir/test_terminal.vim, src/testdir/test_textprop.vim, src/testdir/test_utf8.vim *** ../vim-9.0.0344/runtime/doc/vim9.txt 2022-06-28 11:21:08.000000000 +0100 --- runtime/doc/vim9.txt 2022-09-01 11:53:19.950585744 +0100 *************** *** 1594,1600 **** *E1211* *E1217* *E1218* *E1219* *E1220* *E1221* *E1222* *E1223* *E1224* *E1225* *E1226* *E1227* *E1228* *E1238* *E1250* *E1251* *E1252* *E1253* ! *E1256* Types are checked for most builtin functions to make it easier to spot mistakes. --- 1618,1624 ---- *E1211* *E1217* *E1218* *E1219* *E1220* *E1221* *E1222* *E1223* *E1224* *E1225* *E1226* *E1227* *E1228* *E1238* *E1250* *E1251* *E1252* *E1253* ! *E1256* *E1297* *E1298* Types are checked for most builtin functions to make it easier to spot mistakes. *** ../vim-9.0.0344/src/errors.h 2022-08-30 19:48:17.198760230 +0100 --- src/errors.h 2022-09-01 11:55:38.561884081 +0100 *************** *** 3318,3322 **** --- 3318,3326 ---- EXTERN char e_can_only_use_left_padding_when_column_is_zero[] INIT(= N_("E1296: Can only use left padding when column is zero")); #endif + #ifdef FEAT_EVAL EXTERN char e_non_null_dict_required_for_argument_nr[] INIT(= N_("E1297: Non-NULL Dictionary required for argument %d")); + EXTERN char e_non_null_list_required_for_argument_nr[] + INIT(= N_("E1298: Non-NULL List required for argument %d")); + #endif *** ../vim-9.0.0344/src/evalfunc.c 2022-08-31 11:25:02.815996919 +0100 --- src/evalfunc.c 2022-09-01 11:53:19.950585744 +0100 *************** *** 3235,3245 **** || check_for_opt_dict_arg(argvars, 2) == FAIL)) return; ! if (argvars[1].v_type != VAR_LIST) ! { ! emsg(_(e_list_required)); return; - } if (argvars[1].vval.v_list == NULL) return; --- 3235,3242 ---- || check_for_opt_dict_arg(argvars, 2) == FAIL)) return; ! if (check_for_list_arg(argvars, 1) == FAIL) return; if (argvars[1].vval.v_list == NULL) return; *** ../vim-9.0.0344/src/filepath.c 2022-08-27 21:24:22.709002324 +0100 --- src/filepath.c 2022-09-01 11:53:19.950585744 +0100 *************** *** 1603,1621 **** return checkitem_common(context, name, NULL); } static int ! readdirex_dict_arg(typval_T *tv, int *cmp) { char_u *compare; ! if (tv->v_type != VAR_DICT) ! { ! emsg(_(e_dictionary_required)); return FAIL; - } ! if (dict_has_key(tv->vval.v_dict, "sort")) ! compare = dict_get_string(tv->vval.v_dict, "sort", FALSE); else { semsg(_(e_dictionary_key_str_required), "sort"); --- 1603,1622 ---- return checkitem_common(context, name, NULL); } + /* + * Process the keys in the Dict argument to the readdir() and readdirex() + * functions. Assumes the Dict argument is the 3rd argument. + */ static int ! readdirex_dict_arg(typval_T *argvars, int *cmp) { char_u *compare; ! if (check_for_nonnull_dict_arg(argvars, 2) == FAIL) return FAIL; ! if (dict_has_key(argvars[2].vval.v_dict, "sort")) ! compare = dict_get_string(argvars[2].vval.v_dict, "sort", FALSE); else { semsg(_(e_dictionary_key_str_required), "sort"); *************** *** 1660,1666 **** expr = &argvars[1]; if (argvars[1].v_type != VAR_UNKNOWN && argvars[2].v_type != VAR_UNKNOWN && ! readdirex_dict_arg(&argvars[2], &sort) == FAIL) return; ret = readdir_core(&ga, path, FALSE, (void *)expr, --- 1661,1667 ---- expr = &argvars[1]; if (argvars[1].v_type != VAR_UNKNOWN && argvars[2].v_type != VAR_UNKNOWN && ! readdirex_dict_arg(argvars, &sort) == FAIL) return; ret = readdir_core(&ga, path, FALSE, (void *)expr, *************** *** 1713,1719 **** expr = &argvars[1]; if (argvars[1].v_type != VAR_UNKNOWN && argvars[2].v_type != VAR_UNKNOWN && ! readdirex_dict_arg(&argvars[2], &sort) == FAIL) return; ret = readdir_core(&ga, path, TRUE, (void *)expr, --- 1714,1720 ---- expr = &argvars[1]; if (argvars[1].v_type != VAR_UNKNOWN && argvars[2].v_type != VAR_UNKNOWN && ! readdirex_dict_arg(argvars, &sort) == FAIL) return; ret = readdir_core(&ga, path, TRUE, (void *)expr, *** ../vim-9.0.0344/src/insexpand.c 2022-08-24 16:48:19.936033180 +0100 --- src/insexpand.c 2022-09-01 11:53:19.954585721 +0100 *************** *** 2930,2938 **** if (!undo_allowed()) return; ! if (argvars[1].v_type != VAR_LIST || argvars[1].vval.v_list == NULL) ! emsg(_(e_invalid_argument)); ! else { startcol = (int)tv_get_number_chk(&argvars[0], NULL); if (startcol > 0) --- 2930,2936 ---- if (!undo_allowed()) return; ! if (check_for_nonnull_list_arg(argvars, 1) != FAIL) { startcol = (int)tv_get_number_chk(&argvars[0], NULL); if (startcol > 0) *************** *** 3143,3153 **** if (argvars[0].v_type != VAR_UNKNOWN) { ! if (argvars[0].v_type != VAR_LIST) ! { ! emsg(_(e_list_required)); return; - } what_list = argvars[0].vval.v_list; } get_complete_info(what_list, rettv->vval.v_dict); --- 3141,3148 ---- if (argvars[0].v_type != VAR_UNKNOWN) { ! if (check_for_list_arg(argvars, 0) == FAIL) return; what_list = argvars[0].vval.v_list; } get_complete_info(what_list, rettv->vval.v_dict); *** ../vim-9.0.0344/src/list.c 2022-08-31 11:25:02.815996919 +0100 --- src/list.c 2022-09-01 11:53:19.954585721 +0100 *************** *** 1519,1529 **** || check_for_opt_string_arg(argvars, 1) == FAIL)) return; ! if (argvars[0].v_type != VAR_LIST) ! { ! emsg(_(e_list_required)); return; - } if (argvars[0].vval.v_list == NULL) return; --- 1519,1526 ---- || check_for_opt_string_arg(argvars, 1) == FAIL)) return; ! if (check_for_list_arg(argvars, 0) == FAIL) return; if (argvars[0].vval.v_list == NULL) return; *************** *** 1728,1738 **** || check_for_opt_bool_arg(argvars, 1) == FAIL)) return; ! if (argvars[0].v_type != VAR_LIST) ! { ! emsg(_(e_invalid_argument)); return; - } l = argvars[0].vval.v_list; if (l == NULL) --- 1725,1732 ---- || check_for_opt_bool_arg(argvars, 1) == FAIL)) return; ! if (check_for_list_arg(argvars, 0) == FAIL) return; l = argvars[0].vval.v_list; if (l == NULL) *** ../vim-9.0.0344/src/match.c 2022-08-14 14:16:07.991582244 +0100 --- src/match.c 2022-09-01 11:53:19.954585721 +0100 *************** *** 1087,1097 **** || check_for_opt_number_arg(argvars, 1) == FAIL)) return; ! if (argvars[0].v_type != VAR_LIST) ! { ! emsg(_(e_list_required)); return; - } win = get_optional_window(argvars, 1); if (win == NULL) return; --- 1087,1094 ---- || check_for_opt_number_arg(argvars, 1) == FAIL)) return; ! if (check_for_list_arg(argvars, 0) == FAIL) return; win = get_optional_window(argvars, 1); if (win == NULL) return; *** ../vim-9.0.0344/src/mbyte.c 2022-08-16 17:50:33.959764427 +0100 --- src/mbyte.c 2022-09-01 11:53:19.954585721 +0100 *************** *** 5535,5548 **** size_t cw_table_size_save; char *error = NULL; ! if (in_vim9script() && check_for_list_arg(argvars, 0) == FAIL) return; - if (argvars[0].v_type != VAR_LIST || argvars[0].vval.v_list == NULL) - { - emsg(_(e_list_required)); - return; - } l = argvars[0].vval.v_list; if (l->lv_len == 0) { --- 5535,5543 ---- size_t cw_table_size_save; char *error = NULL; ! if (check_for_nonnull_list_arg(argvars, 0) == FAIL) return; l = argvars[0].vval.v_list; if (l->lv_len == 0) { *** ../vim-9.0.0344/src/proto/typval.pro 2022-08-30 19:48:17.202760217 +0100 --- src/proto/typval.pro 2022-09-01 11:53:19.954585721 +0100 *************** *** 20,25 **** --- 20,26 ---- int check_for_opt_bool_arg(typval_T *args, int idx); int check_for_blob_arg(typval_T *args, int idx); int check_for_list_arg(typval_T *args, int idx); + int check_for_nonnull_list_arg(typval_T *args, int idx); int check_for_opt_list_arg(typval_T *args, int idx); int check_for_dict_arg(typval_T *args, int idx); int check_for_nonnull_dict_arg(typval_T *args, int idx); *** ../vim-9.0.0344/src/sign.c 2022-08-30 19:48:17.206760205 +0100 --- src/sign.c 2022-09-01 11:53:19.954585721 +0100 *************** *** 2660,2670 **** if (in_vim9script() && check_for_list_arg(argvars, 0) == FAIL) return; ! if (argvars[0].v_type != VAR_LIST) ! { ! emsg(_(e_list_required)); return; - } // Process the List of sign attributes FOR_ALL_LIST_ITEMS(argvars[0].vval.v_list, li) --- 2660,2667 ---- if (in_vim9script() && check_for_list_arg(argvars, 0) == FAIL) return; ! if (check_for_list_arg(argvars, 0) == FAIL) return; // Process the List of sign attributes FOR_ALL_LIST_ITEMS(argvars[0].vval.v_list, li) *************** *** 2888,2898 **** if (in_vim9script() && check_for_list_arg(argvars, 0) == FAIL) return; ! if (argvars[0].v_type != VAR_LIST) ! { ! emsg(_(e_list_required)); return; - } FOR_ALL_LIST_ITEMS(argvars[0].vval.v_list, li) { --- 2885,2892 ---- if (in_vim9script() && check_for_list_arg(argvars, 0) == FAIL) return; ! if (check_for_list_arg(argvars, 0) == FAIL) return; FOR_ALL_LIST_ITEMS(argvars[0].vval.v_list, li) { *** ../vim-9.0.0344/src/terminal.c 2022-08-30 19:48:17.206760205 +0100 --- src/terminal.c 2022-09-01 11:53:19.954585721 +0100 *************** *** 6462,6472 **** if (term->tl_vterm == NULL) return; ! if (argvars[1].v_type != VAR_LIST || argvars[1].vval.v_list == NULL) ! { ! emsg(_(e_list_required)); return; ! } if (argvars[1].vval.v_list->lv_first == &range_list_item || argvars[1].vval.v_list->lv_len != 16) { --- 6462,6470 ---- if (term->tl_vterm == NULL) return; ! if (check_for_nonnull_list_arg(argvars, 1) == FAIL) return; ! if (argvars[1].vval.v_list->lv_first == &range_list_item || argvars[1].vval.v_list->lv_len != 16) { *** ../vim-9.0.0344/src/textprop.c 2022-08-30 19:48:17.206760205 +0100 --- src/textprop.c 2022-09-01 11:53:19.958585697 +0100 *************** *** 348,358 **** || check_for_list_arg(argvars, 1) == FAIL) return; ! if (argvars[1].vval.v_list == NULL) ! { ! emsg(_(e_list_required)); return; - } dict = argvars[0].vval.v_dict; if (dict == NULL || !dict_has_key(dict, "type")) --- 348,355 ---- || check_for_list_arg(argvars, 1) == FAIL) return; ! if (check_for_nonnull_list_arg(argvars, 1) == FAIL) return; dict = argvars[0].vval.v_dict; if (dict == NULL || !dict_has_key(dict, "type")) *** ../vim-9.0.0344/src/typval.c 2022-08-30 19:48:17.206760205 +0100 --- src/typval.c 2022-09-01 11:53:19.958585697 +0100 *************** *** 509,514 **** --- 509,531 ---- } /* + * Give an error and return FAIL unless "args[idx]" is a non-NULL list. + */ + int + check_for_nonnull_list_arg(typval_T *args, int idx) + { + if (check_for_list_arg(args, idx) == FAIL) + return FAIL; + + if (args[idx].vval.v_list == NULL) + { + semsg(_(e_non_null_list_required_for_argument_nr), idx + 1); + return FAIL; + } + return OK; + } + + /* * Check for an optional list argument at 'idx' */ int *** ../vim-9.0.0344/src/testdir/test_functions.vim 2022-08-30 19:48:17.206760205 +0100 --- src/testdir/test_functions.vim 2022-09-01 11:53:19.954585721 +0100 *************** *** 2244,2252 **** exe "lang collate" collate " 5) Errors ! call assert_fails('call readdir(dir, 1, 1)', 'E715:') call assert_fails('call readdir(dir, 1, #{sorta: 1})') call assert_fails('call readdirex(dir, 1, #{sorta: 1})') " 6) ignore other values in dict let files = readdir(dir, '1', #{sort: 'c'}) --- 2244,2255 ---- exe "lang collate" collate " 5) Errors ! call assert_fails('call readdir(dir, 1, 1)', 'E1206:') call assert_fails('call readdir(dir, 1, #{sorta: 1})') + call assert_fails('call readdir(dir, 1, test_null_dict())', 'E1297:') + call assert_fails('call readdirex(dir, 1, 1)', 'E1206:') call assert_fails('call readdirex(dir, 1, #{sorta: 1})') + call assert_fails('call readdirex(dir, 1, test_null_dict())', 'E1297:') " 6) ignore other values in dict let files = readdir(dir, '1', #{sort: 'c'}) *************** *** 2285,2291 **** func Test_call() call assert_equal(3, call('len', [123])) call assert_equal(3, 'len'->call([123])) ! call assert_fails("call call('len', 123)", 'E714:') call assert_equal(0, call('', [])) call assert_equal(0, call('len', test_null_list())) --- 2288,2294 ---- func Test_call() call assert_equal(3, call('len', [123])) call assert_equal(3, 'len'->call([123])) ! call assert_fails("call call('len', 123)", 'E1211:') call assert_equal(0, call('', [])) call assert_equal(0, call('len', test_null_list())) *************** *** 2580,2586 **** " list2str() call assert_equal('ABC', list2str(range(65, 67))) ! call assert_fails('let s = list2str(5)', 'E474:') " lock() let thelist = range(5) --- 2583,2589 ---- " list2str() call assert_equal('ABC', list2str(range(65, 67))) ! call assert_fails('let s = list2str(5)', 'E1211:') " lock() let thelist = range(5) *** ../vim-9.0.0344/src/testdir/test_ins_complete.vim 2022-08-29 23:01:42.053954524 +0100 --- src/testdir/test_ins_complete.vim 2022-09-01 11:53:19.954585721 +0100 *************** *** 673,686 **** func ListColors() call complete(col('.'), "blue") endfunc ! call assert_fails('exe "normal i\=ListColors()\"', 'E474:') func ListMonths() call complete(col('.'), test_null_list()) endfunc ! call assert_fails('exe "normal i\=ListMonths()\"', 'E474:') delfunc ListColors delfunc ListMonths ! call assert_fails('call complete_info({})', 'E714:') call assert_equal([], complete_info(['items']).items) endfunc --- 673,686 ---- func ListColors() call complete(col('.'), "blue") endfunc ! call assert_fails('exe "normal i\=ListColors()\"', 'E1211:') func ListMonths() call complete(col('.'), test_null_list()) endfunc ! call assert_fails('exe "normal i\=ListMonths()\"', 'E1298:') delfunc ListColors delfunc ListMonths ! call assert_fails('call complete_info({})', 'E1211:') call assert_equal([], complete_info(['items']).items) endfunc *** ../vim-9.0.0344/src/testdir/test_match.vim 2022-02-10 19:08:54.000000000 +0000 --- src/testdir/test_match.vim 2022-09-01 11:53:19.954585721 +0100 *************** *** 95,101 **** call assert_equal(0, setmatches([])) call assert_equal(0, setmatches([{'group': 'MyGroup1', 'pattern': 'TODO', 'priority': 10, 'id': 1}])) call clearmatches() ! call assert_fails('call setmatches(0)', 'E714:') call assert_fails('call setmatches([0])', 'E474:') call assert_fails("call setmatches([{'wrong key': 'wrong value'}])", 'E474:') call assert_equal(-1, setmatches([{'group' : 'Search', 'priority' : 10, 'id' : 5, 'pos1' : {}}])) --- 95,101 ---- call assert_equal(0, setmatches([])) call assert_equal(0, setmatches([{'group': 'MyGroup1', 'pattern': 'TODO', 'priority': 10, 'id': 1}])) call clearmatches() ! call assert_fails('call setmatches(0)', 'E1211:') call assert_fails('call setmatches([0])', 'E474:') call assert_fails("call setmatches([{'wrong key': 'wrong value'}])", 'E474:') call assert_equal(-1, setmatches([{'group' : 'Search', 'priority' : 10, 'id' : 5, 'pos1' : {}}])) *** ../vim-9.0.0344/src/testdir/test_method.vim 2022-08-30 18:26:16.104885465 +0100 --- src/testdir/test_method.vim 2022-09-01 11:53:19.954585721 +0100 *************** *** 52,58 **** call assert_fails("let x = d->insert(0)", 'E899:') call assert_true(d->has_key('two')) call assert_equal([['one', 1], ['two', 2], ['three', 3]], d->items()) ! call assert_fails("let x = d->join()", 'E714:') call assert_equal(['one', 'two', 'three'], d->keys()) call assert_equal(3, d->len()) call assert_equal(#{one: 2, two: 3, three: 4}, d->map('v:val + 1')) --- 52,58 ---- call assert_fails("let x = d->insert(0)", 'E899:') call assert_true(d->has_key('two')) call assert_equal([['one', 1], ['two', 2], ['three', 3]], d->items()) ! call assert_fails("let x = d->join()", 'E1211:') call assert_equal(['one', 'two', 'three'], d->keys()) call assert_equal(3, d->len()) call assert_equal(#{one: 2, two: 3, three: 4}, d->map('v:val + 1')) *** ../vim-9.0.0344/src/testdir/test_signs.vim 2022-08-30 19:48:17.206760205 +0100 --- src/testdir/test_signs.vim 2022-09-01 11:53:19.954585721 +0100 *************** *** 2010,2016 **** " Invalid arguments call assert_equal([], sign_placelist([])) ! call assert_fails('call sign_placelist({})', "E714:") call assert_fails('call sign_placelist([[]])', "E715:") call assert_fails('call sign_placelist(["abc"])', "E715:") call assert_fails('call sign_placelist([100])', "E715:") --- 2010,2016 ---- " Invalid arguments call assert_equal([], sign_placelist([])) ! call assert_fails('call sign_placelist({})', "E1211:") call assert_fails('call sign_placelist([[]])', "E715:") call assert_fails('call sign_placelist(["abc"])', "E715:") call assert_fails('call sign_placelist([100])', "E715:") *************** *** 2021,2027 **** " Invalid arguments call assert_equal([], []->sign_unplacelist()) ! call assert_fails('call sign_unplacelist({})', "E714:") call assert_fails('call sign_unplacelist([[]])', "E715:") call assert_fails('call sign_unplacelist(["abc"])', "E715:") call assert_fails('call sign_unplacelist([100])', "E715:") --- 2021,2027 ---- " Invalid arguments call assert_equal([], []->sign_unplacelist()) ! call assert_fails('call sign_unplacelist({})', "E1211:") call assert_fails('call sign_unplacelist([[]])', "E715:") call assert_fails('call sign_unplacelist(["abc"])', "E715:") call assert_fails('call sign_unplacelist([100])', "E715:") *** ../vim-9.0.0344/src/testdir/test_terminal.vim 2022-08-30 19:48:17.210760193 +0100 --- src/testdir/test_terminal.vim 2022-09-01 11:53:19.958585697 +0100 *************** *** 2065,2071 **** let colors[4] = 'Invalid' call assert_fails('call term_setansicolors(buf, colors)', 'E254:') ! call assert_fails('call term_setansicolors(buf, {})', 'E714:') set tgc& call StopShellInTerminal(buf) --- 2065,2071 ---- let colors[4] = 'Invalid' call assert_fails('call term_setansicolors(buf, colors)', 'E254:') ! call assert_fails('call term_setansicolors(buf, {})', 'E1211:') set tgc& call StopShellInTerminal(buf) *** ../vim-9.0.0344/src/testdir/test_textprop.vim 2022-08-30 19:48:17.210760193 +0100 --- src/testdir/test_textprop.vim 2022-09-01 11:53:19.958585697 +0100 *************** *** 381,387 **** call assert_fails('call prop_add_list(#{type: "one"}, [[2, 2, 2, 2], [3, 20, 3, 22]])', 'E964:') call assert_fails('eval #{type: "one"}->prop_add_list([[2, 2, 2, 2], [3, 20, 3, 22]])', 'E964:') call assert_fails('call prop_add_list(test_null_dict(), [[2, 2, 2]])', 'E965:') ! call assert_fails('call prop_add_list(#{type: "one"}, test_null_list())', 'E714:') call assert_fails('call prop_add_list(#{type: "one"}, [test_null_list()])', 'E714:') call DeletePropTypes() bw! --- 381,387 ---- call assert_fails('call prop_add_list(#{type: "one"}, [[2, 2, 2, 2], [3, 20, 3, 22]])', 'E964:') call assert_fails('eval #{type: "one"}->prop_add_list([[2, 2, 2, 2], [3, 20, 3, 22]])', 'E964:') call assert_fails('call prop_add_list(test_null_dict(), [[2, 2, 2]])', 'E965:') ! call assert_fails('call prop_add_list(#{type: "one"}, test_null_list())', 'E1298:') call assert_fails('call prop_add_list(#{type: "one"}, [test_null_list()])', 'E714:') call DeletePropTypes() bw! *** ../vim-9.0.0344/src/testdir/test_utf8.vim 2022-01-24 10:57:05.000000000 +0000 --- src/testdir/test_utf8.vim 2022-09-01 11:53:19.958585697 +0100 *************** *** 168,174 **** call setcellwidths([]) ! call assert_fails('call setcellwidths(1)', 'E714:') call assert_fails('call setcellwidths([1, 2, 0])', 'E1109:') --- 168,174 ---- call setcellwidths([]) ! call assert_fails('call setcellwidths(1)', 'E1211:') call assert_fails('call setcellwidths([1, 2, 0])', 'E1109:') *** ../vim-9.0.0344/src/version.c 2022-09-01 11:31:41.971132670 +0100 --- src/version.c 2022-09-01 11:54:45.450137606 +0100 *************** *** 709,710 **** --- 709,712 ---- { /* Add new patch number below this line */ + /**/ + 345, /**/ -- ARTHUR: What are you going to do. bleed on me? "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// \\\ \\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///