comparison src/time.c @ 25384:e8e2c4d33b9b v8.2.3229

patch 8.2.3229: Vim9: runtime and compile time type checks are not the same Commit: https://github.com/vim/vim/commit/4490ec4e839e45a2e6923c265c7e9e64c240b805 Author: Yegappan Lakshmanan <yegappan@yahoo.com> Date: Tue Jul 27 22:00:44 2021 +0200 patch 8.2.3229: Vim9: runtime and compile time type checks are not the same Problem: Vim9: runtime and compile time type checks are not the same. Solution: Add more runtime type checks for builtin functions. (Yegappan Lakshmanan, closes #8646)
author Bram Moolenaar <Bram@vim.org>
date Tue, 27 Jul 2021 22:15:06 +0200
parents 75031a22be39
children f8bcd21e6e24
comparison
equal deleted inserted replaced
25383:510e4fcb5363 25384:e8e2c4d33b9b
172 long n1, n2; 172 long n1, n2;
173 173
174 if (rettv_list_alloc(rettv) != OK) 174 if (rettv_list_alloc(rettv) != OK)
175 return; 175 return;
176 176
177 if (in_vim9script()
178 && (check_for_opt_list_arg(argvars, 0) == FAIL
179 || (argvars[0].v_type != VAR_UNKNOWN
180 && check_for_opt_list_arg(argvars, 1) == FAIL)))
181 return;
182
177 if (argvars[0].v_type == VAR_UNKNOWN) 183 if (argvars[0].v_type == VAR_UNKNOWN)
178 { 184 {
179 // No arguments: get current time. 185 // No arguments: get current time.
180 profile_start(&res); 186 profile_start(&res);
181 } 187 }
226 # endif 232 # endif
227 233
228 rettv->v_type = VAR_FLOAT; 234 rettv->v_type = VAR_FLOAT;
229 rettv->vval.v_float = 0; 235 rettv->vval.v_float = 0;
230 # ifdef FEAT_RELTIME 236 # ifdef FEAT_RELTIME
237 if (in_vim9script() && check_for_list_arg(argvars, 0) == FAIL)
238 return;
239
231 if (list2proftime(&argvars[0], &tm) == OK) 240 if (list2proftime(&argvars[0], &tm) == OK)
232 rettv->vval.v_float = profile_float(&tm); 241 rettv->vval.v_float = profile_float(&tm);
233 else if (in_vim9script()) 242 else if (in_vim9script())
234 emsg(_(e_invarg)); 243 emsg(_(e_invarg));
235 # endif 244 # endif
247 # endif 256 # endif
248 257
249 rettv->v_type = VAR_STRING; 258 rettv->v_type = VAR_STRING;
250 rettv->vval.v_string = NULL; 259 rettv->vval.v_string = NULL;
251 # ifdef FEAT_RELTIME 260 # ifdef FEAT_RELTIME
261 if (in_vim9script() && check_for_list_arg(argvars, 0) == FAIL)
262 return;
263
252 if (list2proftime(&argvars[0], &tm) == OK) 264 if (list2proftime(&argvars[0], &tm) == OK)
253 rettv->vval.v_string = vim_strsave((char_u *)profile_msg(&tm)); 265 rettv->vval.v_string = vim_strsave((char_u *)profile_msg(&tm));
254 else if (in_vim9script()) 266 else if (in_vim9script())
255 emsg(_(e_invarg)); 267 emsg(_(e_invarg));
256 # endif 268 # endif
339 struct tm tmval; 351 struct tm tmval;
340 char_u *fmt; 352 char_u *fmt;
341 char_u *str; 353 char_u *str;
342 vimconv_T conv; 354 vimconv_T conv;
343 char_u *enc; 355 char_u *enc;
356
357 if (in_vim9script()
358 && (check_for_string_arg(argvars, 0) == FAIL
359 || check_for_string_arg(argvars, 1) == FAIL))
360 return;
344 361
345 CLEAR_FIELD(tmval); 362 CLEAR_FIELD(tmval);
346 tmval.tm_isdst = -1; 363 tmval.tm_isdst = -1;
347 fmt = tv_get_string(&argvars[0]); 364 fmt = tv_get_string(&argvars[0]);
348 str = tv_get_string(&argvars[1]); 365 str = tv_get_string(&argvars[1]);
752 { 769 {
753 timer_T *timer = NULL; 770 timer_T *timer = NULL;
754 771
755 if (rettv_list_alloc(rettv) != OK) 772 if (rettv_list_alloc(rettv) != OK)
756 return; 773 return;
774
775 if (in_vim9script() && check_for_opt_number_arg(argvars, 0) == FAIL)
776 return;
777
757 if (argvars[0].v_type != VAR_UNKNOWN) 778 if (argvars[0].v_type != VAR_UNKNOWN)
758 { 779 {
759 if (argvars[0].v_type != VAR_NUMBER) 780 if (argvars[0].v_type != VAR_NUMBER)
760 emsg(_(e_number_expected)); 781 emsg(_(e_number_expected));
761 else 782 else
846 */ 867 */
847 void 868 void
848 f_timer_stop(typval_T *argvars, typval_T *rettv UNUSED) 869 f_timer_stop(typval_T *argvars, typval_T *rettv UNUSED)
849 { 870 {
850 timer_T *timer; 871 timer_T *timer;
872
873 if (in_vim9script() && check_for_number_arg(argvars, 0) == FAIL)
874 return;
851 875
852 if (argvars[0].v_type != VAR_NUMBER) 876 if (argvars[0].v_type != VAR_NUMBER)
853 { 877 {
854 emsg(_(e_number_expected)); 878 emsg(_(e_number_expected));
855 return; 879 return;