Mercurial > vim
comparison src/typval.c @ 25368:1ffa8eb30353 v8.2.3221
patch 8.2.3221: Vim9: argument types are not checked at compile time
Commit: https://github.com/vim/vim/commit/a764e73d4ffc5d046807c757eaacb9b0a5408152
Author: Yegappan Lakshmanan <yegappan@yahoo.com>
Date: Sun Jul 25 15:57:32 2021 +0200
patch 8.2.3221: Vim9: argument types are not checked at compile time
Problem: Vim9: argument types are not checked at compile time.
Solution: Add several more type checks. (Yegappan Lakshmanan, closes https://github.com/vim/vim/issues/8632)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 25 Jul 2021 16:00:05 +0200 |
parents | 75031a22be39 |
children | e8e2c4d33b9b |
comparison
equal
deleted
inserted
replaced
25367:90ed0a369ac3 | 25368:1ffa8eb30353 |
---|---|
420 return (args[idx].v_type == VAR_UNKNOWN | 420 return (args[idx].v_type == VAR_UNKNOWN |
421 || check_for_number_arg(args, idx) != FAIL); | 421 || check_for_number_arg(args, idx) != FAIL); |
422 } | 422 } |
423 | 423 |
424 /* | 424 /* |
425 * Give an error and return FAIL unless "args[idx]" is a float or a number. | |
426 */ | |
427 int | |
428 check_for_float_or_nr_arg(typval_T *args, int idx) | |
429 { | |
430 if (args[idx].v_type != VAR_FLOAT && args[idx].v_type != VAR_NUMBER) | |
431 { | |
432 if (idx >= 0) | |
433 semsg(_(e_number_required_for_argument_nr), idx + 1); | |
434 else | |
435 emsg(_(e_numberreq)); | |
436 return FAIL; | |
437 } | |
438 return OK; | |
439 } | |
440 | |
441 /* | |
425 * Give an error and return FAIL unless "args[idx]" is a bool. | 442 * Give an error and return FAIL unless "args[idx]" is a bool. |
426 */ | 443 */ |
427 int | 444 int |
428 check_for_bool_arg(typval_T *args, int idx) | 445 check_for_bool_arg(typval_T *args, int idx) |
429 { | 446 { |
648 else | 665 else |
649 emsg(_(e_stringreq)); | 666 emsg(_(e_stringreq)); |
650 return FAIL; | 667 return FAIL; |
651 } | 668 } |
652 return OK; | 669 return OK; |
670 } | |
671 | |
672 /* | |
673 * Check for an optional string or list argument at 'idx' | |
674 */ | |
675 int | |
676 check_for_opt_string_or_list_arg(typval_T *args, int idx) | |
677 { | |
678 return (args[idx].v_type == VAR_UNKNOWN | |
679 || check_for_string_or_list_arg(args, idx)); | |
653 } | 680 } |
654 | 681 |
655 /* | 682 /* |
656 * Give an error and return FAIL unless "args[idx]" is a list or a blob. | 683 * Give an error and return FAIL unless "args[idx]" is a list or a blob. |
657 */ | 684 */ |