Mercurial > vim
comparison src/typval.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 | 1ffa8eb30353 |
children | a6c347a0c6e3 |
comparison
equal
deleted
inserted
replaced
25383:510e4fcb5363 | 25384:e8e2c4d33b9b |
---|---|
428 check_for_float_or_nr_arg(typval_T *args, int idx) | 428 check_for_float_or_nr_arg(typval_T *args, int idx) |
429 { | 429 { |
430 if (args[idx].v_type != VAR_FLOAT && args[idx].v_type != VAR_NUMBER) | 430 if (args[idx].v_type != VAR_FLOAT && args[idx].v_type != VAR_NUMBER) |
431 { | 431 { |
432 if (idx >= 0) | 432 if (idx >= 0) |
433 semsg(_(e_number_required_for_argument_nr), idx + 1); | 433 semsg(_(e_float_or_number_required_for_argument_nr), idx + 1); |
434 else | 434 else |
435 emsg(_(e_numberreq)); | 435 emsg(_(e_numberreq)); |
436 return FAIL; | 436 return FAIL; |
437 } | 437 } |
438 return OK; | 438 return OK; |
566 } | 566 } |
567 return OK; | 567 return OK; |
568 } | 568 } |
569 | 569 |
570 /* | 570 /* |
571 * Check for an optional job argument at 'idx'. | |
572 */ | |
573 int | |
574 check_for_opt_job_arg(typval_T *args, int idx) | |
575 { | |
576 return (args[idx].v_type == VAR_UNKNOWN | |
577 || check_for_job_arg(args, idx) != FAIL); | |
578 } | |
579 | |
580 /* | |
571 * Give an error and return FAIL unless "args[idx]" is a string or | 581 * Give an error and return FAIL unless "args[idx]" is a string or |
572 * a number. | 582 * a number. |
573 */ | 583 */ |
574 int | 584 int |
575 check_for_string_or_number_arg(typval_T *args, int idx) | 585 check_for_string_or_number_arg(typval_T *args, int idx) |
576 { | 586 { |
577 if (args[idx].v_type != VAR_STRING && args[idx].v_type != VAR_NUMBER) | 587 if (args[idx].v_type != VAR_STRING && args[idx].v_type != VAR_NUMBER) |
578 { | 588 { |
579 if (idx >= 0) | 589 if (idx >= 0) |
580 semsg(_(e_string_required_for_argument_nr), idx + 1); | 590 semsg(_(e_string_or_number_required_for_argument_nr), idx + 1); |
581 else | 591 else |
582 emsg(_(e_stringreq)); | 592 emsg(_(e_stringreq)); |
583 return FAIL; | 593 return FAIL; |
584 } | 594 } |
585 return OK; | 595 return OK; |
642 check_for_string_or_blob_arg(typval_T *args, int idx) | 652 check_for_string_or_blob_arg(typval_T *args, int idx) |
643 { | 653 { |
644 if (args[idx].v_type != VAR_STRING && args[idx].v_type != VAR_BLOB) | 654 if (args[idx].v_type != VAR_STRING && args[idx].v_type != VAR_BLOB) |
645 { | 655 { |
646 if (idx >= 0) | 656 if (idx >= 0) |
647 semsg(_(e_string_required_for_argument_nr), idx + 1); | 657 semsg(_(e_string_or_blob_required_for_argument_nr), idx + 1); |
648 else | 658 else |
649 emsg(_(e_stringreq)); | 659 emsg(_(e_stringreq)); |
650 return FAIL; | 660 return FAIL; |
651 } | 661 } |
652 return OK; | 662 return OK; |
659 check_for_string_or_list_arg(typval_T *args, int idx) | 669 check_for_string_or_list_arg(typval_T *args, int idx) |
660 { | 670 { |
661 if (args[idx].v_type != VAR_STRING && args[idx].v_type != VAR_LIST) | 671 if (args[idx].v_type != VAR_STRING && args[idx].v_type != VAR_LIST) |
662 { | 672 { |
663 if (idx >= 0) | 673 if (idx >= 0) |
664 semsg(_(e_string_required_for_argument_nr), idx + 1); | 674 semsg(_(e_string_or_list_required_for_argument_nr), idx + 1); |
665 else | 675 else |
666 emsg(_(e_stringreq)); | 676 emsg(_(e_stringreq)); |
667 return FAIL; | 677 return FAIL; |
668 } | 678 } |
669 return OK; | 679 return OK; |
678 return (args[idx].v_type == VAR_UNKNOWN | 688 return (args[idx].v_type == VAR_UNKNOWN |
679 || check_for_string_or_list_arg(args, idx)); | 689 || check_for_string_or_list_arg(args, idx)); |
680 } | 690 } |
681 | 691 |
682 /* | 692 /* |
693 * Give an error and return FAIL unless "args[idx]" is a string or a dict. | |
694 */ | |
695 int | |
696 check_for_string_or_dict_arg(typval_T *args, int idx) | |
697 { | |
698 if (args[idx].v_type != VAR_STRING && args[idx].v_type != VAR_DICT) | |
699 { | |
700 if (idx >= 0) | |
701 semsg(_(e_string_or_dict_required_for_argument_nr), idx + 1); | |
702 else | |
703 emsg(_(e_stringreq)); | |
704 return FAIL; | |
705 } | |
706 return OK; | |
707 } | |
708 | |
709 /* | |
710 * Give an error and return FAIL unless "args[idx]" is a string or a number | |
711 * or a list. | |
712 */ | |
713 int | |
714 check_for_string_or_number_or_list_arg(typval_T *args, int idx) | |
715 { | |
716 if (args[idx].v_type != VAR_STRING | |
717 && args[idx].v_type != VAR_NUMBER | |
718 && args[idx].v_type != VAR_LIST) | |
719 { | |
720 if (idx >= 0) | |
721 semsg(_(e_string_or_number_or_list_required_for_argument_nr), idx + 1); | |
722 else | |
723 emsg(_(e_stringreq)); | |
724 return FAIL; | |
725 } | |
726 return OK; | |
727 } | |
728 | |
729 /* | |
730 * Give an error and return FAIL unless "args[idx]" is a string or a list | |
731 * or a dict. | |
732 */ | |
733 int | |
734 check_for_string_or_list_or_dict_arg(typval_T *args, int idx) | |
735 { | |
736 if (args[idx].v_type != VAR_STRING | |
737 && args[idx].v_type != VAR_LIST | |
738 && args[idx].v_type != VAR_DICT) | |
739 { | |
740 if (idx >= 0) | |
741 semsg(_(e_string_or_list_or_dict_required_for_argument_nr), idx + 1); | |
742 else | |
743 emsg(_(e_stringreq)); | |
744 return FAIL; | |
745 } | |
746 return OK; | |
747 } | |
748 | |
749 /* | |
683 * Give an error and return FAIL unless "args[idx]" is a list or a blob. | 750 * Give an error and return FAIL unless "args[idx]" is a list or a blob. |
684 */ | 751 */ |
685 int | 752 int |
686 check_for_list_or_blob_arg(typval_T *args, int idx) | 753 check_for_list_or_blob_arg(typval_T *args, int idx) |
687 { | 754 { |
688 if (args[idx].v_type != VAR_LIST && args[idx].v_type != VAR_BLOB) | 755 if (args[idx].v_type != VAR_LIST && args[idx].v_type != VAR_BLOB) |
689 { | 756 { |
690 if (idx >= 0) | 757 if (idx >= 0) |
691 semsg(_(e_list_required_for_argument_nr), idx + 1); | 758 semsg(_(e_list_or_blob_required_for_argument_nr), idx + 1); |
759 else | |
760 emsg(_(e_listreq)); | |
761 return FAIL; | |
762 } | |
763 return OK; | |
764 } | |
765 | |
766 /* | |
767 * Give an error and return FAIL unless "args[idx]" is a list or dict | |
768 */ | |
769 int | |
770 check_for_list_or_dict_arg(typval_T *args, int idx) | |
771 { | |
772 if (args[idx].v_type != VAR_LIST | |
773 && args[idx].v_type != VAR_DICT) | |
774 { | |
775 if (idx >= 0) | |
776 semsg(_(e_list_or_dict_required_for_argument_nr), idx + 1); | |
692 else | 777 else |
693 emsg(_(e_listreq)); | 778 emsg(_(e_listreq)); |
694 return FAIL; | 779 return FAIL; |
695 } | 780 } |
696 return OK; | 781 return OK; |
706 if (args[idx].v_type != VAR_LIST | 791 if (args[idx].v_type != VAR_LIST |
707 && args[idx].v_type != VAR_DICT | 792 && args[idx].v_type != VAR_DICT |
708 && args[idx].v_type != VAR_BLOB) | 793 && args[idx].v_type != VAR_BLOB) |
709 { | 794 { |
710 if (idx >= 0) | 795 if (idx >= 0) |
711 semsg(_(e_list_required_for_argument_nr), idx + 1); | 796 semsg(_(e_list_or_dict_or_blob_required_for_argument_nr), idx + 1); |
712 else | 797 else |
713 emsg(_(e_listreq)); | 798 emsg(_(e_listreq)); |
714 return FAIL; | 799 return FAIL; |
715 } | 800 } |
716 return OK; | 801 return OK; |
717 } | 802 } |
718 | 803 |
719 /* | 804 /* |
720 * Give an error and return FAIL unless "args[idx]" is a buffer number or a | 805 * Give an error and return FAIL unless "args[idx]" is an optional buffer |
721 * dict. | 806 * number or a dict. |
722 */ | 807 */ |
723 int | 808 int |
724 check_for_buffer_or_dict_arg(typval_T *args, int idx) | 809 check_for_opt_buffer_or_dict_arg(typval_T *args, int idx) |
725 { | 810 { |
726 if (args[idx].v_type != VAR_STRING | 811 if (args[idx].v_type != VAR_UNKNOWN |
812 && args[idx].v_type != VAR_STRING | |
727 && args[idx].v_type != VAR_NUMBER | 813 && args[idx].v_type != VAR_NUMBER |
728 && args[idx].v_type != VAR_DICT) | 814 && args[idx].v_type != VAR_DICT) |
729 { | 815 { |
730 if (idx >= 0) | 816 if (idx >= 0) |
731 semsg(_(e_string_required_for_argument_nr), idx + 1); | 817 semsg(_(e_string_required_for_argument_nr), idx + 1); |