Mercurial > vim
comparison src/typval.c @ 25338:e2be9f3c5907 v8.2.3206
patch 8.2.3206: Vim9: argument types are not checked at compile time
Commit: https://github.com/vim/vim/commit/0ad871dc4dfe1026e14931a55c225616b63f4c5b
Author: Yegappan Lakshmanan <yegappan@yahoo.com>
Date: Fri Jul 23 20:37:56 2021 +0200
patch 8.2.3206: 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/8611)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Fri, 23 Jul 2021 20:45:05 +0200 |
parents | 7e620652bd13 |
children | 75031a22be39 |
comparison
equal
deleted
inserted
replaced
25337:0e5cb14de298 | 25338:e2be9f3c5907 |
---|---|
504 return (args[idx].v_type == VAR_UNKNOWN | 504 return (args[idx].v_type == VAR_UNKNOWN |
505 || check_for_dict_arg(args, idx) != FAIL); | 505 || check_for_dict_arg(args, idx) != FAIL); |
506 } | 506 } |
507 | 507 |
508 /* | 508 /* |
509 * Give an error and return FAIL unless "args[idx]" is a blob. | |
510 */ | |
511 int | |
512 check_for_blob_arg(typval_T *args, int idx) | |
513 { | |
514 if (args[idx].v_type != VAR_BLOB) | |
515 { | |
516 if (idx >= 0) | |
517 semsg(_(e_blob_required_for_argument_nr), idx + 1); | |
518 else | |
519 emsg(_(e_blobreq)); | |
520 return FAIL; | |
521 } | |
522 return OK; | |
523 } | |
524 | |
525 /* | |
526 * Give an error and return FAIL unless "args[idx]" is a channel or a job. | 509 * Give an error and return FAIL unless "args[idx]" is a channel or a job. |
527 */ | 510 */ |
528 int | 511 int |
529 check_for_chan_or_job_arg(typval_T *args, int idx) | 512 check_for_chan_or_job_arg(typval_T *args, int idx) |
530 { | 513 { |
623 return (args[idx].v_type == VAR_UNKNOWN | 606 return (args[idx].v_type == VAR_UNKNOWN |
624 || check_for_lnum_arg(args, idx)); | 607 || check_for_lnum_arg(args, idx)); |
625 } | 608 } |
626 | 609 |
627 /* | 610 /* |
628 * Give an error and return FAIL unless "args[idx]" is a string or | 611 * Give an error and return FAIL unless "args[idx]" is a string or a blob. |
629 * a blob. | |
630 */ | 612 */ |
631 int | 613 int |
632 check_for_string_or_blob_arg(typval_T *args, int idx) | 614 check_for_string_or_blob_arg(typval_T *args, int idx) |
633 { | 615 { |
634 if (args[idx].v_type != VAR_STRING && args[idx].v_type != VAR_BLOB) | 616 if (args[idx].v_type != VAR_STRING && args[idx].v_type != VAR_BLOB) |
641 } | 623 } |
642 return OK; | 624 return OK; |
643 } | 625 } |
644 | 626 |
645 /* | 627 /* |
646 * Give an error and return FAIL unless "args[idx]" is a string or | 628 * Give an error and return FAIL unless "args[idx]" is a string or a list. |
647 * a list. | |
648 */ | 629 */ |
649 int | 630 int |
650 check_for_string_or_list_arg(typval_T *args, int idx) | 631 check_for_string_or_list_arg(typval_T *args, int idx) |
651 { | 632 { |
652 if (args[idx].v_type != VAR_STRING && args[idx].v_type != VAR_LIST) | 633 if (args[idx].v_type != VAR_STRING && args[idx].v_type != VAR_LIST) |
659 } | 640 } |
660 return OK; | 641 return OK; |
661 } | 642 } |
662 | 643 |
663 /* | 644 /* |
664 * Give an error and return FAIL unless "args[idx]" is a buffer | 645 * Give an error and return FAIL unless "args[idx]" is a list or a blob. |
665 * number or a dict. | 646 */ |
647 int | |
648 check_for_list_or_blob_arg(typval_T *args, int idx) | |
649 { | |
650 if (args[idx].v_type != VAR_LIST && args[idx].v_type != VAR_BLOB) | |
651 { | |
652 if (idx >= 0) | |
653 semsg(_(e_list_required_for_argument_nr), idx + 1); | |
654 else | |
655 emsg(_(e_listreq)); | |
656 return FAIL; | |
657 } | |
658 return OK; | |
659 } | |
660 | |
661 /* | |
662 * Give an error and return FAIL unless "args[idx]" is a list or dict or a | |
663 * blob. | |
664 */ | |
665 int | |
666 check_for_list_or_dict_or_blob_arg(typval_T *args, int idx) | |
667 { | |
668 if (args[idx].v_type != VAR_LIST | |
669 && args[idx].v_type != VAR_DICT | |
670 && args[idx].v_type != VAR_BLOB) | |
671 { | |
672 if (idx >= 0) | |
673 semsg(_(e_list_required_for_argument_nr), idx + 1); | |
674 else | |
675 emsg(_(e_listreq)); | |
676 return FAIL; | |
677 } | |
678 return OK; | |
679 } | |
680 | |
681 /* | |
682 * Give an error and return FAIL unless "args[idx]" is a buffer number or a | |
683 * dict. | |
666 */ | 684 */ |
667 int | 685 int |
668 check_for_buffer_or_dict_arg(typval_T *args, int idx) | 686 check_for_buffer_or_dict_arg(typval_T *args, int idx) |
669 { | 687 { |
670 if (args[idx].v_type != VAR_STRING | 688 if (args[idx].v_type != VAR_STRING |