Mercurial > vim
diff 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 |
line wrap: on
line diff
--- a/src/typval.c +++ b/src/typval.c @@ -430,7 +430,7 @@ check_for_float_or_nr_arg(typval_T *args if (args[idx].v_type != VAR_FLOAT && args[idx].v_type != VAR_NUMBER) { if (idx >= 0) - semsg(_(e_number_required_for_argument_nr), idx + 1); + semsg(_(e_float_or_number_required_for_argument_nr), idx + 1); else emsg(_(e_numberreq)); return FAIL; @@ -568,6 +568,16 @@ check_for_job_arg(typval_T *args, int id } /* + * Check for an optional job argument at 'idx'. + */ + int +check_for_opt_job_arg(typval_T *args, int idx) +{ + return (args[idx].v_type == VAR_UNKNOWN + || check_for_job_arg(args, idx) != FAIL); +} + +/* * Give an error and return FAIL unless "args[idx]" is a string or * a number. */ @@ -577,7 +587,7 @@ check_for_string_or_number_arg(typval_T if (args[idx].v_type != VAR_STRING && args[idx].v_type != VAR_NUMBER) { if (idx >= 0) - semsg(_(e_string_required_for_argument_nr), idx + 1); + semsg(_(e_string_or_number_required_for_argument_nr), idx + 1); else emsg(_(e_stringreq)); return FAIL; @@ -644,7 +654,7 @@ check_for_string_or_blob_arg(typval_T *a if (args[idx].v_type != VAR_STRING && args[idx].v_type != VAR_BLOB) { if (idx >= 0) - semsg(_(e_string_required_for_argument_nr), idx + 1); + semsg(_(e_string_or_blob_required_for_argument_nr), idx + 1); else emsg(_(e_stringreq)); return FAIL; @@ -661,7 +671,7 @@ check_for_string_or_list_arg(typval_T *a if (args[idx].v_type != VAR_STRING && args[idx].v_type != VAR_LIST) { if (idx >= 0) - semsg(_(e_string_required_for_argument_nr), idx + 1); + semsg(_(e_string_or_list_required_for_argument_nr), idx + 1); else emsg(_(e_stringreq)); return FAIL; @@ -680,6 +690,63 @@ check_for_opt_string_or_list_arg(typval_ } /* + * Give an error and return FAIL unless "args[idx]" is a string or a dict. + */ + int +check_for_string_or_dict_arg(typval_T *args, int idx) +{ + if (args[idx].v_type != VAR_STRING && args[idx].v_type != VAR_DICT) + { + if (idx >= 0) + semsg(_(e_string_or_dict_required_for_argument_nr), idx + 1); + else + emsg(_(e_stringreq)); + return FAIL; + } + return OK; +} + +/* + * Give an error and return FAIL unless "args[idx]" is a string or a number + * or a list. + */ + int +check_for_string_or_number_or_list_arg(typval_T *args, int idx) +{ + if (args[idx].v_type != VAR_STRING + && args[idx].v_type != VAR_NUMBER + && args[idx].v_type != VAR_LIST) + { + if (idx >= 0) + semsg(_(e_string_or_number_or_list_required_for_argument_nr), idx + 1); + else + emsg(_(e_stringreq)); + return FAIL; + } + return OK; +} + +/* + * Give an error and return FAIL unless "args[idx]" is a string or a list + * or a dict. + */ + int +check_for_string_or_list_or_dict_arg(typval_T *args, int idx) +{ + if (args[idx].v_type != VAR_STRING + && args[idx].v_type != VAR_LIST + && args[idx].v_type != VAR_DICT) + { + if (idx >= 0) + semsg(_(e_string_or_list_or_dict_required_for_argument_nr), idx + 1); + else + emsg(_(e_stringreq)); + return FAIL; + } + return OK; +} + +/* * Give an error and return FAIL unless "args[idx]" is a list or a blob. */ int @@ -688,7 +755,25 @@ check_for_list_or_blob_arg(typval_T *arg if (args[idx].v_type != VAR_LIST && args[idx].v_type != VAR_BLOB) { if (idx >= 0) - semsg(_(e_list_required_for_argument_nr), idx + 1); + semsg(_(e_list_or_blob_required_for_argument_nr), idx + 1); + else + emsg(_(e_listreq)); + return FAIL; + } + return OK; +} + +/* + * Give an error and return FAIL unless "args[idx]" is a list or dict + */ + int +check_for_list_or_dict_arg(typval_T *args, int idx) +{ + if (args[idx].v_type != VAR_LIST + && args[idx].v_type != VAR_DICT) + { + if (idx >= 0) + semsg(_(e_list_or_dict_required_for_argument_nr), idx + 1); else emsg(_(e_listreq)); return FAIL; @@ -708,7 +793,7 @@ check_for_list_or_dict_or_blob_arg(typva && args[idx].v_type != VAR_BLOB) { if (idx >= 0) - semsg(_(e_list_required_for_argument_nr), idx + 1); + semsg(_(e_list_or_dict_or_blob_required_for_argument_nr), idx + 1); else emsg(_(e_listreq)); return FAIL; @@ -717,13 +802,14 @@ check_for_list_or_dict_or_blob_arg(typva } /* - * Give an error and return FAIL unless "args[idx]" is a buffer number or a - * dict. + * Give an error and return FAIL unless "args[idx]" is an optional buffer + * number or a dict. */ int -check_for_buffer_or_dict_arg(typval_T *args, int idx) +check_for_opt_buffer_or_dict_arg(typval_T *args, int idx) { - if (args[idx].v_type != VAR_STRING + if (args[idx].v_type != VAR_UNKNOWN + && args[idx].v_type != VAR_STRING && args[idx].v_type != VAR_NUMBER && args[idx].v_type != VAR_DICT) {