diff options
author | Yegappan Lakshmanan <yegappan@yahoo.com> | 2021-07-21 19:09:09 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2021-07-21 19:09:09 +0200 |
commit | cd9172077bc8c0aafddf2e5367cc0ae2c00c8ff7 (patch) | |
tree | d460cabb1f58286f763089e7a9552be6c21059f3 /src/typval.c | |
parent | 189663bdac1156237c49925f77bd197c1bdea12c (diff) | |
download | vim-git-cd9172077bc8c0aafddf2e5367cc0ae2c00c8ff7.tar.gz |
patch 8.2.3194: Vim9: argument types are not checked at compile timev8.2.3194
Problem: Vim9: argument types are not checked at compile time.
Solution: Add several more type checks, simplify some. (Yegappan
Lakshmanan, closes #8598)
Diffstat (limited to 'src/typval.c')
-rw-r--r-- | src/typval.c | 88 |
1 files changed, 55 insertions, 33 deletions
diff --git a/src/typval.c b/src/typval.c index 29c925d66..b73c5002b 100644 --- a/src/typval.c +++ b/src/typval.c @@ -575,31 +575,63 @@ check_for_string_or_number_arg(typval_T *args, int idx) } /* - * Give an error and return FAIL unless "args[idx]" is a string or - * a number (buffer) + * Check for an optional string or number argument at 'idx'. + */ + int +check_for_opt_string_or_number_arg(typval_T *args, int idx) +{ + return (args[idx].v_type == VAR_UNKNOWN + || check_for_string_or_number_arg(args, idx) != FAIL); +} + +/* + * Give an error and return FAIL unless "args[idx]" is a buffer number. + * Buffer number can be a number or a string. */ int check_for_buffer_arg(typval_T *args, int idx) { - 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); - else - emsg(_(e_stringreq)); - return FAIL; - } - return OK; + return check_for_string_or_number_arg(args, idx); } /* - * Give an error and return FAIL unless "args[idx]" is a string or - * a number (line) + * Check for an optional buffer argument at 'idx' + */ + int +check_for_opt_buffer_arg(typval_T *args, int idx) +{ + return (args[idx].v_type == VAR_UNKNOWN + || check_for_buffer_arg(args, idx)); +} + +/* + * Give an error and return FAIL unless "args[idx]" is a line number. + * Line number can be a number or a string. */ int check_for_lnum_arg(typval_T *args, int idx) { - if (args[idx].v_type != VAR_STRING && args[idx].v_type != VAR_NUMBER) + return check_for_string_or_number_arg(args, idx); +} + +/* + * Check for an optional line number argument at 'idx' + */ + int +check_for_opt_lnum_arg(typval_T *args, int idx) +{ + return (args[idx].v_type == VAR_UNKNOWN + || check_for_lnum_arg(args, idx)); +} + +/* + * Give an error and return FAIL unless "args[idx]" is a string or + * a blob. + */ + int +check_for_string_or_blob_arg(typval_T *args, int idx) +{ + 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); @@ -612,14 +644,12 @@ check_for_lnum_arg(typval_T *args, int idx) /* * Give an error and return FAIL unless "args[idx]" is a string or - * a number (line) + * a list. */ int -check_for_opt_lnum_arg(typval_T *args, int idx) +check_for_string_or_list_arg(typval_T *args, int idx) { - if (args[idx].v_type != VAR_UNKNOWN - && args[idx].v_type != VAR_STRING - && args[idx].v_type != VAR_NUMBER) + 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); @@ -631,23 +661,15 @@ check_for_opt_lnum_arg(typval_T *args, int idx) } /* - * Check for an optional string or number argument at 'idx' + * Give an error and return FAIL unless "args[idx]" is a buffer + * number or a dict. */ int -check_for_opt_string_or_number_arg(typval_T *args, int idx) +check_for_buffer_or_dict_arg(typval_T *args, int idx) { - return (args[idx].v_type == VAR_UNKNOWN - || check_for_string_or_number_arg(args, idx) != FAIL); -} - -/* - * Give an error and return FAIL unless "args[idx]" is a string or - * a blob. - */ - int -check_for_string_or_blob_arg(typval_T *args, int idx) -{ - if (args[idx].v_type != VAR_STRING && args[idx].v_type != VAR_BLOB) + if (args[idx].v_type != VAR_STRING + && args[idx].v_type != VAR_NUMBER + && args[idx].v_type != VAR_DICT) { if (idx >= 0) semsg(_(e_string_required_for_argument_nr), idx + 1); |