comparison src/search.c @ 29994:86eb4aba16c3 v9.0.0335

patch 9.0.0335: checks for Dictionary argument often give a vague error Commit: https://github.com/vim/vim/commit/04c4c5746e15884768d2cb41370c3276a196cd4c Author: Yegappan Lakshmanan <yegappan@yahoo.com> Date: Tue Aug 30 19:48:24 2022 +0100 patch 9.0.0335: checks for Dictionary argument often give a vague error Problem: Checks for Dictionary argument often give a vague error message. Solution: Give a useful error message. (Yegappan Lakshmanan, closes https://github.com/vim/vim/issues/11009)
author Bram Moolenaar <Bram@vim.org>
date Tue, 30 Aug 2022 21:00:05 +0200
parents 89e1d67814a9
children 6c1a9d7a931f
comparison
equal deleted inserted replaced
29993:8dd1900432a0 29994:86eb4aba16c3
762 * Look for a match somewhere in line "lnum". 762 * Look for a match somewhere in line "lnum".
763 */ 763 */
764 col = at_first_line && (options & SEARCH_COL) ? pos->col 764 col = at_first_line && (options & SEARCH_COL) ? pos->col
765 : (colnr_T)0; 765 : (colnr_T)0;
766 nmatched = vim_regexec_multi(&regmatch, win, buf, 766 nmatched = vim_regexec_multi(&regmatch, win, buf,
767 lnum, col, timed_out); 767 lnum, col, timed_out);
768 // vim_regexec_multi() may clear "regprog" 768 // vim_regexec_multi() may clear "regprog"
769 if (regmatch.regprog == NULL) 769 if (regmatch.regprog == NULL)
770 break; 770 break;
771 // Abort searching on an error (e.g., out of stack). 771 // Abort searching on an error (e.g., out of stack).
772 if (called_emsg > called_emsg_before || *timed_out) 772 if (called_emsg > called_emsg_before || *timed_out)
1070 * Stop the search if wrapscan isn't set, "stop_lnum" is 1070 * Stop the search if wrapscan isn't set, "stop_lnum" is
1071 * specified, after an interrupt, after a match and after looping 1071 * specified, after an interrupt, after a match and after looping
1072 * twice. 1072 * twice.
1073 */ 1073 */
1074 if (!p_ws || stop_lnum != 0 || got_int 1074 if (!p_ws || stop_lnum != 0 || got_int
1075 || called_emsg > called_emsg_before || *timed_out 1075 || called_emsg > called_emsg_before || *timed_out
1076 #ifdef FEAT_SEARCH_EXTRA 1076 #ifdef FEAT_SEARCH_EXTRA
1077 || break_loop 1077 || break_loop
1078 #endif 1078 #endif
1079 || found || loop) 1079 || found || loop)
1080 break; 1080 break;
1081 1081
1082 /* 1082 /*
1083 * If 'wrapscan' is set we continue at the other end of the file. 1083 * If 'wrapscan' is set we continue at the other end of the file.
1084 * If 'shortmess' does not contain 's', we give a message. 1084 * If 'shortmess' does not contain 's', we give a message.
4093 dict_T *dict; 4093 dict_T *dict;
4094 dictitem_T *di; 4094 dictitem_T *di;
4095 listitem_T *li; 4095 listitem_T *li;
4096 int error = FALSE; 4096 int error = FALSE;
4097 4097
4098 if (argvars[0].v_type != VAR_DICT || argvars[0].vval.v_dict == NULL) 4098 if (check_for_nonnull_dict_arg(argvars, 0) == FAIL)
4099 {
4100 emsg(_(e_dictionary_required));
4101 return; 4099 return;
4102 }
4103 dict = argvars[0].vval.v_dict; 4100 dict = argvars[0].vval.v_dict;
4104 di = dict_find(dict, (char_u *)"timeout", -1); 4101 di = dict_find(dict, (char_u *)"timeout", -1);
4105 if (di != NULL) 4102 if (di != NULL)
4106 { 4103 {
4107 timeout = (long)tv_get_number_chk(&di->di_tv, &error); 4104 timeout = (long)tv_get_number_chk(&di->di_tv, &error);
4813 if (argvars[2].v_type != VAR_UNKNOWN) 4810 if (argvars[2].v_type != VAR_UNKNOWN)
4814 { 4811 {
4815 dict_T *d; 4812 dict_T *d;
4816 dictitem_T *di; 4813 dictitem_T *di;
4817 4814
4818 if (argvars[2].v_type != VAR_DICT || argvars[2].vval.v_dict == NULL) 4815 if (check_for_nonnull_dict_arg(argvars, 2) == FAIL)
4819 {
4820 emsg(_(e_dictionary_required));
4821 return; 4816 return;
4822 }
4823 4817
4824 // To search a dict, either a callback function or a key can be 4818 // To search a dict, either a callback function or a key can be
4825 // specified. 4819 // specified.
4826 d = argvars[2].vval.v_dict; 4820 d = argvars[2].vval.v_dict;
4827 if ((di = dict_find(d, (char_u *)"key", -1)) != NULL) 4821 if ((di = dict_find(d, (char_u *)"key", -1)) != NULL)